Home >Backend Development >PHP Tutorial >An example of using redis queue operation in php

An example of using redis queue operation in php

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 09:05:39898browse
  1. $redis = new Redis();
  2. $redis->connect('127.0.0.1',6379);
  3. while(True){
  4. try{
  5. $value = 'value_'.date('Y-m-d H:i:s');
  6. $redis->LPUSH('key1',$value);
  7. sleep(rand()%3);
  8. echo $value."n";
  9. }catch(Exception $e){
  10. echo $e->getMessage()."n";
  11. }
  12. }
  13. ?>
复制代码

例2,出队操作:

  1. $redis = new Redis();
  2. $redis->pconnect('127.0.0.1',6379);
  3. while(True){
  4. try{
  5. echo $redis->LPOP('key1')."n";
  6. }catch(Exception $e){
  7. echo $e->getMessage()."n";
  8. }
  9. sleep(rand()%3);
  10. }
  11. ?>
复制代码


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn