1 入队操作 2 <?php 3 $redis = new Redis(); 4 $redis->connect('127.0.0.1',6379); 5 while(True){ 6 try{ 7 $value = 'value_'.date('Y-m-d H:i:s'); 8 $redis->LPUSH('key1',$value); 9 sleep(rand()%3); 10 echo $value."\n"; 11 }catch(Exception $e){ 12 echo $e->getMessage()."\n"; 13 } 14 } 15 ?> 16 17 出队操作 18 <?php 19 $redis = new Redis(); 20 $redis->pconnect('127.0.0.1',6379); 21 while(True){ 22 try{ 23 echo $redis->LPOP('key1')."\n"; 24 }catch(Exception $e){ 25 echo $e->getMessage()."\n"; 26 } 27 sleep(rand()%3); 28 } 29 ?>