设为首页收藏本站

Scripts 学盟

 找回密码
 加入学盟

QQ登录

只需一步,快速开始

查看: 963|回复: 0
打印 上一主题 下一主题

Redis函数使用(二) [复制链接]

Rank: 8Rank: 8

跳转到指定楼层
1#
那个谁 发表于 2012-2-18 10:41:33 |只看该作者 |倒序浏览

Publish
说明:
发表内容到某一个通道。注意,该方法可能在未来里发生改变

参数:
Channel:

Messsage:string

范例:
$redis->publish('chan-1', 'hello, world!'); // send message.
exists
说明:
验证指定的值是否存在
参数:
Key

返回值:
成功返回true 失败返回false

范例:
$redis->set('key', 'value');
$redis->exists('key'); /*  TRUE */
$redis->exists('NonExistingKey'); /* FALSE */

incr, incrBy
说明:
key中的值进行自增.如果第二个参数存在,它将被用来作为整数值递增

参数:
Key

Value

返回值:
返回新value
范例:
$redis->incr('key1'); /* key1 didn't exists, set to 0 before the increment */
                      /* and now has the value 1  */

$redis->incr('key1'); /* 2 */
$redis->incr('key1'); /* 3 */
$redis->incr('key1'); /* 4 */
$redis->incrBy('key1', 10); /* 14 */
decr, decrBy
说明:
删掉key中的值,用法同incr
范例:
$redis->decr('key1'); /* key1 didn't exists, set to 0 before the increment */
                      /* and now has the value -1  */

$redis->decr('key1'); /* -2 */
$redis->decr('key1'); /* -3 */
$redis->decrBy('key1', 10); /* -13 */
getMultiple
说明:
返回一组数据的值,如果这个数组中的key值不存在,则返回false
参数:
Array

返回值:
Array

范例:
$redis->set('key1', 'value1');
$redis->set('key2', 'value2');
$redis->set('key3', 'value3');
$redis->getMultiple(array('key1', 'key2', 'key3')); /* array('value1', 'value2', 'value3');
$redis->getMultiple(array('key0', 'key1', 'key5')); /* array(`FALSE`, 'value2', `FALSE`);
lPush
说明:
在名称为key的list左边(头)添加一个值为value的 元素,如果这个key值不存在则创建一个。如果key值存在并且不是一个list,则返回false

参数:
Key

Value

返回值:
返回key值得长度。

范例:
$redis->delete('key1');
$redis->lPush('key1', 'C'); // returns 1
$redis->lPush('key1', 'B'); // returns 2
$redis->lPush('key1', 'A'); // returns 3
/* key1 now points to the following list: [ 'A', 'B', 'C' ] */
rPush
说明:
在名称为key的list右边(尾)添加一个值为value的 元素,如果这个key值不存在则创建一个。如果key值存在并且不是一个list,则返回false

参数:
Key

Value

返回值:


返回key值得长度。

范例:
$redis->delete('key1');
$redis->rPush('key1', 'A'); // returns 1
$redis->rPush('key1', 'B'); // returns 2
$redis->rPush('key1', 'C'); // returns 3
/* key1 now points to the following list: [ 'A', 'B', 'C' ] */
分享到: QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
分享分享0 收藏收藏0
您需要登录后才可以回帖 登录 | 加入学盟

手机版|Scripts 学盟   |

GMT+8, 2024-4-29 09:15 , Processed in 1.076469 second(s), 11 queries .

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部