Exemplo n.º 1
2
function doQueue()
{
    global $statusArr;
    $pid = posix_getpid();
    $statusArr[$pid]++;
    $redis = new Redis();
    $redis->connect('127.0.0.1', '6379');
    // 这个中间可以是处理逻辑
    $data = "you are so beautiful!";
    $key = "test:lo";
    $redis->rpush($key, $data);
    $data = $redis->lpop($key);
    $redis->close();
}
Exemplo n.º 2
1
 public function redisConsumerAction()
 {
     $config = Yaf_Application::app()->getConfig();
     $queue = 'test_queue';
     $host = $config['redis_host'];
     $port = $config['redis_port'];
     $redis = new Redis();
     $redis->connect($host, $port);
     $data = $redis->lpop($queue);
     echo $data;
     die;
 }
Exemplo n.º 3
1
<?php

$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$redis->select(2);
$channel = $argv[1];
// channel
while (TRUE) {
    $data = array();
    while ($msg = $redis->lpop('channel' . $channel)) {
        $data[] = $msg;
    }
    print_r($data);
    sleep(1);
}
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function flushQueue(\Swift_Transport $transport, &$failedRecipients = null)
 {
     if (!$this->redis->llen($this->key)) {
         return 0;
     }
     if (!$transport->isStarted()) {
         $transport->start();
     }
     $failedRecipients = (array) $failedRecipients;
     $count = 0;
     $time = time();
     while ($message = unserialize($this->redis->lpop($this->key))) {
         $count += $transport->send($message, $failedRecipients);
         if ($this->getMessageLimit() && $count >= $this->getMessageLimit()) {
             break;
         }
         if ($this->getTimeLimit() && time() - $time >= $this->getTimeLimit()) {
             break;
         }
     }
     return $count;
 }
Exemplo n.º 5
0
$log->info("Starting feedwriter process");
// Connect to redis
$redis = new Redis();
while (!$redis->connect("127.0.0.1")) {
    sleep(1);
    $log->warn("Could not connect to redis, retrying");
}
require "Modules/feed/engine/PHPTimeSeries.php";
require "Modules/feed/engine/PHPFina.php";
$engine = array();
$engine[Engine::PHPTIMESERIES] = new PHPTimeSeries($feed_settings['phptimeseries']);
$engine[Engine::PHPFINA] = new PHPFina($feed_settings['phpfina']);
while (true) {
    $len = $redis->llen("feedbuffer");
    for ($i = 0; $i < $len; $i++) {
        $f = explode(",", $redis->lpop("feedbuffer"));
        $feedid = $f[0];
        $timestamp = $f[1];
        $value = $f[2];
        $padding_mode = (int) $f[3];
        $e = $redis->hget("feed:{$feedid}", 'engine');
        if ($padding_mode == 1) {
            $engine[Engine::PHPFINA]->padding_mode = 'join';
        }
        $engine[$e]->prepare($feedid, $timestamp, $value);
        $engine[Engine::PHPFINA]->padding_mode = 'nan';
    }
    $log->info("PHPTimeSeries bytes written: " . $engine[Engine::PHPTIMESERIES]->save());
    $log->info("PHPFina bytes written: " . $engine[Engine::PHPFINA]->save());
    sleep(60);
}
Exemplo n.º 6
0
 function getMap($pid = 0)
 {
     if ($pid <= 0) {
         return;
     }
     $redis = new Redis();
     $redis->pconnect('127.0.0.1', 6379);
     $map = $redis->get('map');
     if (!$map) {
         $tid = $redis->lpop('free');
         $map = array($pid => $tid);
         $redis->set('map', json_encode($map));
     } else {
         $map = json_decode($map, true);
         $tid = $map[$pid];
     }
     //var_dump('map', $map, 'tid', $tid,'pid:', $pid);
     return $tid;
 }
Exemplo n.º 7
0
 public function lpop($key, $value)
 {
     return parent::lpop($this->generateUniqueKey($key), $value);
 }
Exemplo n.º 8
0
 public function removeCurrent()
 {
     $this->redis->lpop($this->tube);
 }
Exemplo n.º 9
0
 public function pop()
 {
     return $this->redis->lpop($this->key);
 }
Exemplo n.º 10
0
<?php

$redis = new Redis();
$redis->connect("127.0.0.1");
$i = 0;
while (true) {
    if (time() - $ltime > 1) {
        $ltime = time();
        print $i . "\n";
        $i = 0;
    }
    if ($redis->llen('myqueue') > 0) {
        // check if there is an item in the queue to process
        $line_str = $redis->lpop('myqueue');
        $i++;
    }
}
     // if throughput is low then increase sleep significantly
     if ($rn == 0) {
         $usleep = 100000;
     }
     // sleep cant be less than zero
     if ($usleep < 0) {
         $usleep = 0;
     }
     echo "Buffer length: " . $buflength . " " . $usleep . " " . $rn . "\n";
     $rn = 0;
 }
 // check if there is an item in the queue to process
 $line_str = false;
 if ($redis->llen('buffer') > 0) {
     // check if there is an item in the queue to process
     $line_str = $redis->lpop('buffer');
 }
 if ($line_str) {
     $rn++;
     // echo $line_str."\n";
     $line_parts = explode(',', $line_str);
     // The first and second value in the csv is userid, time and nodeid
     $userid = $line_parts[0];
     $time = $line_parts[1];
     $nodeid = $line_parts[2];
     // Load current user input meta data
     // It would be good to avoid repeated calls to this
     $dbinputs = $input->get_inputs($userid);
     $tmp = array();
     // For each node input
     $name = 1;
Exemplo n.º 12
0
<?php

$redis = new Redis();
$redis->connect("127.0.0.1", "6379");
// string
$redis->delete("KeyTime");
$redis->mset(array('key111' => "key111", "key222" => "key222"));
echo (int) $redis->exists("key111");
$array = $redis->getMultiple(array("key111", "key222"));
echo "<br>";
print_r($array);
for ($i = 0; $i < 10; $i++) {
    $redis->lpush("list", $i);
}
$redis->lpop("list");
$redis->rpop("list");
echo $redis->lsize("list");
echo $redis->lget("list", 0);
echo $redis->lset("list", 1, "new_value");
$data = $redis->lRange("list", 0, -1);
echo "<pre>";
print_r($data);
$bool = $redis->ltrim("list", 0, 5);
echo $redis->lrem("list", "5");
$bool = $redis->rpoplpush("srcKey", "dstKey");
// SET
for ($i = 0; $i < 10; $i++) {
    $redis->sadd("myset", $i + rand(10, 99));
}
$bool = $redis->srem("myset", 16);
echo (int) $bool;
Exemplo n.º 13
0
<?php

header('Content-Type: text/event-stream;charset=UTF-8');
header('Cache-Control: no-cache');
header("Connection: keep-alive");
set_time_limit(0);
$objRedis = new Redis();
$objRedis->connect("localhost");
$numStateEvents = $objRedis->llen('eventQueue');
for ($i = 0; $i < $numStateEvents; $i++) {
    $objRedis->lpop('eventQueue');
}
while (true) {
    $event = $objRedis->lpop('eventQueue');
    if ($event) {
        echo "data: {$event}\n\n";
        ob_flush();
        flush();
    }
}
Exemplo n.º 14
0
//结果:int(3)
var_dump($redis->rpush("test", "444")) . '<br>';
//结果:int(4)
/**
lpop

描述:返回和移除列表的第一个元素
参数:key
返回值:成功返回第一个元素的值 ,失败返回false
*/
$redis->delete('test');
$redis->lpush("test", "111");
$redis->lpush("test", "222");
$redis->rpush("test", "333");
$redis->rpush("test", "444");
var_dump($redis->lpop("test")) . '<br>';
//结果:string(3) "222"
/**
rpop

描述:返回和移除列表的最后一个元素
参数:key
返回值:成功返回最后一个元素的值 ,失败返回false
*/
$redis->delete('test');
$redis->lpush("test", "111");
$redis->lpush("test", "222");
$redis->rpush("test", "333");
$redis->rpush("test", "444");
var_dump($redis->rpop("test")) . '<br>';
//结果:string(3) "444"