首页 >php教程 >php手册 >redis---队列操作的例子(php)

redis---队列操作的例子(php)

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原创
2016-06-13 10:48:311365浏览

入队操作

01

02 $redis = new Redis();

03 $redis->connect('127.0.0.1',6379);

04 while(True){

05     try{

06         $value = 'value_'.date('Y-m-d H:i:s');

07         $redis->LPUSH('key1',$value);

08         sleep(rand()%3);

09         echo $value."\n";

10     }catch(Exception $e){

11         echo $e->getMessage()."\n";

12     }

13 }

14 ?>

 

出队操作

01

02 $redis = new Redis();

03 $redis->pconnect('127.0.0.1',6379);

04 while(True){

05     try{

06         echo $redis->LPOP('key1')."\n";

07     }catch(Exception $e){

08         echo $e->getMessage()."\n";

09     }

10     sleep(rand()%3);

11
 }?>
 

 

摘自  zhuangge
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn