redis消息队列相关函数
2016-10-20 11:16
417 查看
public function lPush( $key, $value1, $value2 = null, $valueN = null ) { $redis->lPush('l', 'v1', 'v2', 'v3', 'v4') // int(4) var_dump( $redis->lRange('l', 0, -1) ); /* Output: * array(4) { * [0]=> string(2) "v4" * [1]=> string(2) "v3" * [2]=> string(2) "v2" * [3]=> string(2) "v1" * } */ } public function rPush( $key, $value1, $value2 = null, $valueN = null ) { $redis->rPush('l', 'v1', 'v2', 'v3', 'v4'); // int(4) var_dump( $redis->lRange('l', 0, -1) ); /* Output: * array(4) { * [0]=> string(2) "v1" * [1]=> string(2) "v2" * [2]=> string(2) "v3" * [3]=> string(2) "v4" * } */ } public function lPushx( $key, $value ) { $redis->delete('key1'); $redis->lPushx('key1', 'A'); // returns 0 $redis->lPush('key1', 'A'); // returns 1 $redis->lPushx('key1', 'B'); // returns 2 $redis->lPushx('key1', 'C'); // returns 3 // key1 now points to the following list: [ 'A', 'B', 'C' ] } public function rPushx( $key, $value ) { $redis->delete('key1'); $redis->rPushx('key1', 'A'); // returns 0 $redis->rPush('key1', 'A'); // returns 1 $redis->rPushx('key1', 'B'); // returns 2 $redis->rPushx('key1', 'C'); // returns 3 // key1 now points to the following list: [ 'A', 'B', 'C' ] } public function lPop( $key ) { $redis->rPush('key1', 'A'); $redis->rPush('key1', 'B'); $redis->rPush('key1', 'C'); // key1 => [ 'A', 'B', 'C' ] $redis->lPop('key1'); // key1 => [ 'B', 'C' ] } public function rPop( $key ) { $redis->rPush('key1', 'A'); $redis->rPush('key1', 'B'); $redis->rPush('key1', 'C'); // key1 => [ 'A', 'B', 'C' ] $redis->rPop('key1'); // key1 => [ 'A', 'B' ] } public function blPop( array $keys ) { // Non blocking feature $redis->lPush('key1', 'A'); $redis->delete('key2'); $redis->blPop('key1', 'key2', 10); // array('key1', 'A') // OR $redis->blPop(array('key1', 'key2'), 10); // array('key1', 'A') $redis->brPop('key1', 'key2', 10); // array('key1', 'A') // OR $redis->brPop(array('key1', 'key2'), 10); // array('key1', 'A') // Blocking feature // process 1 $redis->delete('key1'); $redis->blPop('key1', 10); // blocking for 10 seconds // process 2 $redis->lPush('key1', 'A'); // process 1 // array('key1', 'A') is returned } public function brPop( array $keys ) { // Non blocking feature $redis->lPush('key1', 'A'); $redis->delete('key2'); $redis->blPop('key1', 'key2', 10); // array('key1', 'A') // OR $redis->blPop(array('key1', 'key2'), 10); // array('key1', 'A') $redis->brPop('key1', 'key2', 10); // array('key1', 'A') // OR $redis->brPop(array('key1', 'key2'), 10); // array('key1', 'A') // Blocking feature // process 1 $redis->delete('key1'); $redis->blPop('key1', 10); // blocking for 10 seconds // process 2 $redis->lPush('key1', 'A'); // process 1 // array('key1', 'A') is returned } public function lLen( $key ) { $redis->rPush('key1', 'A'); $redis->rPush('key1', 'B'); $redis->rPush('key1', 'C'); // key1 => [ 'A', 'B', 'C' ] $redis->lLen('key1'); // 3 $redis->rPop('key1'); $redis->lLen('key1'); // 2 } public function lIndex( $key, $index ) { * $redis->rPush('key1', 'A'); * $redis->rPush('key1', 'B'); * $redis->rPush('key1', 'C'); // key1 => [ 'A', 'B', 'C' ] * $redis->lGet('key1', 0); // 'A' * $redis->lGet('key1', -1); // 'C' * $redis->lGet('key1', 10); // `FALSE` }
相关文章推荐
- linux进程间通信--消息队列相关函数(ftok)详解
- 消息队列相关函数总结
- linux进程间通信--消息队列相关函数(msgget、msgctl、msgsnd、msgrcv)详解
- uC/OS-II 函数之消息队列相关函数
- uC/OS-II 函数之消息队列相关函数
- 关于进程通信的消息队列相关函数
- java redis使用之利用jedis实现redis消息队列
- Java利用Redis实现消息队列
- 详解redis是如何实现队列消息的ack
- 用redis实现支持优先级的消息队列
- 【Redis】Java实现消息队列
- linux网络编程之System V 消息队列(一):消息队列内核结构和msgget、msgctl 函数
- redis消息队列
- Redis消息队列示例
- Redis消息队列示例
- redis实现消息队列
- 消息队列函数(msgget、msgctl、msgsnd、msgrcv)
- PHP下使用Redis消息队列发布微博(复制)
- 消息队列函数(msgget、msgctl、msgsnd、msgrcv)及其范例
- Redis消息队列发布微博