Update test redis
This commit is contained in:
+98
-45
@@ -1,73 +1,126 @@
|
||||
<h1>Hello world!!!</h1>
|
||||
|
||||
<h1>EQN</h1>
|
||||
Testing procedure Redis per EQN...
|
||||
|
||||
<?php
|
||||
require "Predis/Autoloader.php";
|
||||
#Caricamento oggetto redis server: occhio alla sintassi x nostra versione php
|
||||
#PredisAutoloader::register();
|
||||
require "Predis/Autoloader.php";
|
||||
Predis\Autoloader::register();
|
||||
|
||||
try {
|
||||
$redis = new Predis\Client();
|
||||
|
||||
// This connection is for a remote server
|
||||
|
||||
$redis = new Predis\Client(array(
|
||||
"scheme" => "tcp",
|
||||
"host" => "172.16.1.80",
|
||||
#"host" => "redis01",
|
||||
"port" => 6379
|
||||
));
|
||||
|
||||
// Connessione server remoto
|
||||
$redis = new Predis\Client(array(
|
||||
"scheme" => "tcp",
|
||||
#"host" => "172.16.1.80",
|
||||
"host" => "redis01",
|
||||
"port" => 6379
|
||||
));
|
||||
}
|
||||
catch (Exception $e) {
|
||||
die($e->getMessage());
|
||||
}
|
||||
?>
|
||||
inizializzato!
|
||||
Server inizializzato, proseguono test
|
||||
<hr/>
|
||||
<?php
|
||||
#------------------------------------------------------
|
||||
# VALORI DI CONFIGURAZIONE (portare su file ext!!!)
|
||||
#------------------------------------------------------
|
||||
# ScoreList Posizioni
|
||||
$tblPos = "EQN:USERS:POS";
|
||||
$tblLast= "EQN:USERS:UPD";
|
||||
# timeout (x semaforo) della gestione update POSIZIONI sul DB (cancello vecchi, inserisco nuovi): 1 min (poi 5?)
|
||||
$tOutPos2Db = 1;
|
||||
# età massima dei valori a sistema (2 minuti, in prod 30!!!)
|
||||
$maxAgePos = 1;
|
||||
# num record da processare in blocco
|
||||
$nBlockRec = 10;
|
||||
|
||||
# definizione funzioni helper x gestione REDIS dell'oggetto (UserID = numero, DTime in intero fino ai minuti yyMMddHHmm)
|
||||
function salvaPosizione($redis, $tblPos, $tblLast, $User_ID, $Lat, $Lon, $DTime) {
|
||||
# salvo dataora verifica
|
||||
$redis->zadd( $tblLast, $DTime, $User_ID );
|
||||
// # salvo posizione Geolocalizzata
|
||||
// $redis->geoadd( $tblPos, $Lat, $Lon, $User_ID )
|
||||
}
|
||||
|
||||
# $predis->zadd( 'myset', [ "one" => 1, "uno" => 1, "two" => 2, "three" => 3 ] )
|
||||
|
||||
|
||||
|
||||
# Genero un UID univoco con nome server (numerico) + numero casuale
|
||||
$server = gethostname();
|
||||
$adesso = date("F j, Y \a\t g:ia");
|
||||
$redis->set($server,$adesso);
|
||||
$redis->incr($server."_count");
|
||||
$uID = substr($server, 2, 2).rand(0,999999999);
|
||||
# genero coordinate casuali LAT/LON
|
||||
$cLat = rand(-85,85);
|
||||
$cLon = rand(-180,180);
|
||||
$currDT = date("YmdHi");
|
||||
|
||||
$redis->hset("taxi_car", "brand", "Toyota");
|
||||
$redis->hset("taxi_car", "model", "Yaris");
|
||||
$redis->hset("taxi_car", "license number", "RO-01-PHP");
|
||||
$redis->hset("taxi_car", "year of fabrication", 2010);
|
||||
$redis->hset("taxi_car", "nr_starts", 0);
|
||||
echo"Valore | uID: ".$uID." | LAT: ".$cLat." | LON: ".$cLon." | DT: ".$currDT;
|
||||
|
||||
$valore = $redis->get($server);
|
||||
salvaPosizione($redis, $tblPos, $tblLast, $uID, $cLat, $cLon, $currDT);
|
||||
|
||||
echo ($redis->exists($server)) ? "Valore salvato: ".$valore : "Prego salvare valore...";
|
||||
# effettuo update informazione posizione dell'utente (insert/update)
|
||||
|
||||
$taxi_car = $redis->hgetall("taxi_car");
|
||||
echo "<hr/>";
|
||||
echo "All info about taxi car";
|
||||
echo "<pre>";
|
||||
var_dump($taxi_car);
|
||||
echo "</pre>";
|
||||
# verifico semaforo $tOutPos2Db (se devo svuotare e aggiornare DB da redis)
|
||||
|
||||
echo "<hr/>";
|
||||
$list = "PHP Frameworks List";
|
||||
$redis->rpush($list, "Symfony 2");
|
||||
$redis->rpush($list, "Symfony 1.4");
|
||||
$redis->lpush($list, "Zend Framework");
|
||||
# mostro infine count record rimasti!!!
|
||||
|
||||
echo "Number of frameworks in list: " . $redis->llen($list) . "<br>";
|
||||
|
||||
$arList = $redis->lrange($list, 0, -1);
|
||||
echo "<pre>";
|
||||
print_r($arList);
|
||||
echo "</pre>";
|
||||
|
||||
// the last entry in the list
|
||||
echo $redis->rpop($list) . "<br>";
|
||||
// $server = gethostname();
|
||||
// $adesso = date("F j, Y \a\t g:ia");
|
||||
// $redis->set($server,$adesso);
|
||||
// $redis->incr($server."_count");
|
||||
|
||||
// the first entry in the list
|
||||
echo $redis->lpop($list) . "<br>";
|
||||
// $redis->hset("taxi_car", "brand", "Toyota");
|
||||
// $redis->hset("taxi_car", "model", "Yaris");
|
||||
// $redis->hset("taxi_car", "license number", "RO-01-PHP");
|
||||
// $redis->hset("taxi_car", "year of fabrication", 2010);
|
||||
// $redis->hset("taxi_car", "nr_starts", 0);
|
||||
|
||||
// $valore = $redis->get($server);
|
||||
|
||||
// echo ($redis->exists($server)) ? "Valore salvato: ".$valore : "Prego salvare valore...";
|
||||
|
||||
// $taxi_car = $redis->hgetall("taxi_car");
|
||||
// echo "<hr/>";
|
||||
// echo "All info about taxi car";
|
||||
// echo "<pre>";
|
||||
// var_dump($taxi_car);
|
||||
// echo "</pre>";
|
||||
|
||||
// echo "<hr/>";
|
||||
// $list = "PHP Frameworks List";
|
||||
// $redis->rpush($list, "Symfony 2");
|
||||
// $redis->rpush($list, "Symfony 1.4");
|
||||
// $redis->lpush($list, "Zend Framework");
|
||||
|
||||
// echo "Number of frameworks in list: " . $redis->llen($list) . "<br>";
|
||||
|
||||
// $arList = $redis->lrange($list, 0, -1);
|
||||
// echo "<pre>";
|
||||
// print_r($arList);
|
||||
// echo "</pre>";
|
||||
|
||||
// // the last entry in the list
|
||||
// echo $redis->rpop($list) . "<br>";
|
||||
|
||||
// // the first entry in the list
|
||||
// echo $redis->lpop($list) . "<br>";
|
||||
|
||||
// echo "<hr/>";
|
||||
// // set the expiration for next week
|
||||
// $redis->set("expire in 1 week", "I have data for a week");
|
||||
// $redis->expireat("expire in 1 week", strtotime("+1 week"));
|
||||
// $ttl = $redis->ttl("expire in 1 week"); // will be 604800 seconds
|
||||
|
||||
// // set the expiration for one hour
|
||||
// $redis->set("expire in 1 hour", "I have data for an hour");
|
||||
// $redis->expire("expire in 1 hour", 3600);
|
||||
// $ttl = $redis->ttl("expire in 1 hour"); // will be 3600 seconds
|
||||
|
||||
// // never expires
|
||||
// $redis->set("never expire", "I want to leave forever!");
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user