phpredis 嵌套消息队列的方法
public function testxiaoxiduilie() { $redis = /RedisClient::getInstance(); $redis->flushall(); $key1 = "duilieitem1"; $redis->Lpush($key1, 'ccc1'); $redis->Lpush($key1, 'ccc2'); $redis->Lpush($key1, 'ccc3'); $key2 = "duilieitem2"; $redis->Lpush($key2, 'ccc4'); $redis->Lpush($key2, 'ccc5'); $redis->Lpush($key2, 'ccc6'); $redis->Lpush($key2, 'ccc7'); $key = "duilie"; $rpopv = $redis->Lpush($key, $key1); $rpopv = $redis->Lpush($key, $key2); }
递归函数一定要注意 变量要释放!!!
public function duquduilie1() { $redis = /RedisClient::getInstance(); $key = "duilie"; $rpopv = $redis->rPop($key); if (empty($rpopv)) { exit(); // 如果为空就 // usleep(200000); $this->duquduilie1(); } else { //如果取到了 while (1) { $duilieitme = $redis->rPop($rpopv); if (!empty($duilieitme)) { echo '取出duilieitem:' . $duilieitme; echo '</br>'; if (0) { //如果这里出现错误 这个地方需要中断的 $redis->del($rpopv); break; } } else { break; } } $this->duquduilie1(); } } public function duquduilie() { // CLI模式下 配置文件不走过期时间 但是 内存限制还是会走配置文件 ini_set("memory_limit", "1026M"); ob_end_clean(); ob_implicit_flush(1); $this->testxiaoxiduilie(); $this->duquduilie1(); }
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/tech/database/4072.html