phpredis 巢狀訊息佇列的方法
阿新 • • 發佈:2020-11-25
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(); }