Redis::__construct
描述:
创建一个Redis客户端
范例:
$redis = new Redis();

connect, open
描述:
实例连接到一个Redis.
参数:host:
string        port: int
返回值:BOOL
成功返回:TRUE;失败返回:FALSE
范例:
$redis->connect(‘127.0.0.1′, 6379);

get
描述:
获取有关指定键的值
参数:key
返回值:string或BOLL
如果键不存在,则返回 FALSE。否则,与此相关的关键值返回。
范例:
$redis->get(‘key’);

set
描述:
设置关键值参数
参数:Key
Value
返回值:BOOL
范例:
$redis->set(‘key’, ‘value’)

setnx
描述:
如果在数据库中不存在该键,设置关键值参数
参数:key
value
返回值:BOOL
范例:
this−>redis−>setnx(‘key′,‘value′);/∗返回TRUE∗/this->redis->setnx(‘key’, ‘value’); /* 返回 FALSE */

delete
描述:
删除指定的键
参数:一个键,或不确定数目的参数,每一个关键的数组:key1
key2 key3 … keyN
返回值:删除的项数
范例:
redis−>set(‘key1',‘val1');redis->set(‘key2′, ‘val2′);
redis−>set(‘key3',‘val3');redis->set(‘key4′, ‘val4′);
redis−>delete(‘key1',‘key2');/∗返回2∗/redis->delete(array(‘key3′, ‘key4′)); /* 返回 2 */

exists
描述:
验证指定的键是否存在
参数key
返回值:Bool
范例:
this−>set(‘key′,‘value′);this->exists(‘key’); /* 返回TRUE
*/
$this->exists(‘NonExistingKey’); /* 返回FALSE */

incr
描述:
数字递增存储键值键.如果第二个参数被填满,它将被用来作为整数值递增
Increment
the number stored at key by one. If the second argument is filled, it will be
used as the integer value of the increment.
参数:key value:将被添加到键的值
返回值:INT
the new 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 */

decr
描述:
数字递减存储键值。如果第二个参数被填满,它将被用来作为整数值递减
Decrement
the number stored at key by one. If the second argument is filled, it will be
used as the integer value of the decrement.
参数:key value:将被添加到键的值
返回值:INT
the new value
范例:
redis−>decr(‘key1');/∗key1didn′texists,setto0beforetheincrement∗//∗andnowhasthevalue−1∗/redis->decr(‘key1′); /* -2 */
$redis->decr(‘key1′); /* -3 */

getMultiple
描述:
取得所有指定键的值。如果一个或多个键不存在,该数组中该键的值为假
参数:其中包含键值的列表数组
返回值:返回包含所有键的值的数组
范例:
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
描述:
由列表尾部添加字符串值。如果不存在该键则创建该列表。如果该键存在,而且不是一个列表,返回FALSE。
参数:key,value
返回值:LONG
The new length of the list in case of success, FALSE in case of
Failure.
范例:
redis−>delete(‘key1');redis->lPush(‘key1′, ‘C’);
// returns 1
redis−>lPush(‘key1',‘B′);//returns2redis->lPush(‘key1′, ‘A’); // returns 3
/* key1 now points to the
following list: [ 'A', 'B', 'C' ] */

rPush
描述:
由列表头部添加字符串值。如果不存在该键则创建该列表。如果该键存在,而且不是一个列表,返回FALSE。
参数:key,value
返回值:LONG
The new length of the list in case of success, FALSE in case of
Failure.
范例:
redis−>delete(‘key1');redis->lPush(‘key1′, ‘C’);
// returns 1
redis−>lPush(‘key1',‘B′);//returns2redis->lPush(‘key1′, ‘A’); // returns 3
/* key1 now points to the
following list: [ 'A', 'B', 'C' ] */

lPop
描述:
返回和移除列表的最后一个元素
参数:key
返回值:STRING
if command executed successfully BOOL FALSE in case of failure (empty
list)
范例:
redis−>rPush(‘key1',‘A′);redis->rPush(‘key1′,
‘B’);
redis−>rPush(‘key1',‘C′);/∗key1=>[′C′,′B′,′A′]∗/redis->lPop(‘key1′); /* key1 => [ 'B', 'A' ] */

rPop
描述:
返回和移除列表的第一个元素
参数:key
返回值:STRING
if command executed successfully BOOL FALSE in case of failure (empty
list)
范例:
redis−>rPush(‘key1',‘A′);redis->rPush(‘key1′,
‘B’);
redis−>rPush(‘key1',‘C′);/∗key1=>[′C′,′B′,′A′]∗/redis->rPop(‘key1′); /* key1 => [ 'C', 'B' ] */

lSize
描述:
返回的列表的大小。如果列表不存在或为空,该命令返回0。如果该键不是列表,该命令返回FALSE。
参数:Key
返回值:
LONG
The size of the list identified by Key exists.
BOOL FALSE if the data type
identified by Key is not list
范例:
redis−>rPush(‘key1',‘A′);redis->rPush(‘key1′, ‘B’);
redis−>rPush(‘key1',‘C′);/∗key1=>[′C′,′B′,′A′]∗/redis->lSize(‘key1′);/* 3
*/
redis−>rPop(‘key1');redis->lSize(‘key1′);/* 2 */

lGet
描述:
返回指定键存储在列表中指定的元素。 0第一个元素,1第二个…
-1最后一个元素,-2的倒数第二…错误的索引或键不指向列表则返回FALSE。
参数:key index
返回值:
String the
element at this index
Bool FALSE if the key identifies a non-string data
type, or no value corresponds to this index in the list
Key.
范例:
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` */

lSet
描述:
为列表指定的索引赋新的值.
参数:key index
value
返回值:BOOL TRUE if the new value is setted. FALSE if the index is out of
range, or data type identified by key is not a
list.
范例:
redis−>rPush(‘key1',‘A′);redis->rPush(‘key1′,
‘B’);
redis−>rPush(‘key1',‘C′);/∗key1=>[′A′,′B′,′C′]∗/redis->lGet(‘key1′, 0); /* ‘A’ */
redis−>lSet(‘key1',0,‘X′);redis->lGet(‘key1′, 0); /* ‘X’ */

lGetRange
描述:
返回在该区域中的指定键列表中开始到结束存储的指定元素,lGetRange(key,
start, end)。0第一个元素,1第二个元素… -1最后一个元素,-2的倒数第二…
参数:key start
end
返回值:
Array containing the values in specified
range.
范例:
redis−>rPush(‘key1',‘A′);redis->rPush(‘key1′,
‘B’);
redis−>rPush(‘key1',‘C′);redis->lGetRange(‘key1′, 0, -1);
/* array(‘A’, ‘B’, ‘C’)
*/
lRemove
描述:
从列表中从头部开始移除count个匹配的值。如果count为零,所有匹配的元素都被删除。如果count是负数,内容从尾部开始删除。
参数:key
count value
返回值:
LONG the number of elements to remove
BOOL FALSE if
the value identified by key is not a list.
范例:
redis−>lPush(‘key1',‘A′);redis->lPush(‘key1′, ‘B’);
redis−>lPush(‘key1',‘C′);redis->lPush(‘key1′, ‘A’);
redis−>lPush(‘key1',‘A′);redis->lGetRange(‘key1′, 0, -1); /* array(‘A’, ‘A’, ‘C’, ‘B’, ‘A’)
*/
redis−>lRemove(‘key1',‘A′,2);/∗2∗/redis->lGetRange(‘key1′, 0, -1); /* array(‘C’, ‘B’, ‘A’) */

sAdd
描述:
为一个Key添加一个值。如果这个值已经在这个Key中,则返回FALSE。
参数:key
value
返回值:
BOOL TRUE if value didn’t exist and was added successfully,
FALSE if the value is already present.
范例:
redis−>sAdd(‘key1',′set1');/∗TRUE,‘key1'=>′set1'∗/redis->sAdd(‘key1′ , ’set2′);
/* TRUE, ‘key1′ => {’set1′, ’set2′}*/
$redis->sAdd(‘key1′ , ’set2′); /*
FALSE, ‘key1′ => {’set1′, ’set2′}*/

sRemove
描述:
删除Key中指定的value值
参数:key
member
返回值:BOOL TRUE if the member was present in the set, FALSE if it
didn’t.
范例:
redis−>sAdd(‘key1',′set1');redis->sAdd(‘key1′ ,
’set2′);
redis−>sAdd(‘key1',′set3');/∗‘key1'=>′set1',′set2',′set3'∗/redis->sRemove(‘key1′, ’set2′); /* ‘key1′ => {’set1′,
’set3′} */

sMove
描述:
将Key1中的value移动到Key2中
参数:srcKey
dstKey member
返回值:BOOL If the operation is successful, return TRUE. If the
srcKey and/or dstKey didn’t exist, and/or the member didn’t exist in srcKey,
FALSE is returned.
范例:
redis−>sAdd(‘key1',′set11');redis->sAdd(‘key1′ , ’set12′);
redis−>sAdd(‘key1',′set13');/∗‘key1'=>′set11',′set12',′set13'∗/redis->sAdd(‘key2′ , ’set21′);
redis−>sAdd(‘key2',′set22');/∗‘key2'=>′set21',′set22'∗/redis->sMove(‘key1′,
‘key2′, ’set13′); /* ‘key1′ => {’set11′, ’set12′} */
/* ‘key2′ =>
{’set21′, ’set22′, ’set13′} */

sContains
描述:
检查集合中是否存在指定的值。
参数:key
value
返回值:BOOL TRUE if value is a member of the set at key key, FALSE
otherwise.
范例:
redis−>sAdd(‘key1',′set1');redis->sAdd(‘key1′
, ’set2′);
redis−>sAdd(‘key1',′set3');/∗‘key1'=>′set1',′set2',′set3'∗/redis->sContains(‘key1′, ’set1′); /* TRUE
*/
$redis->sContains(‘key1′, ’setX’); /* FALSE */

sSize
描述:
返回集合中存储值的数量
参数:key
返回值:LONG
the cardinality of the set identified by key, 0 if the set doesn’t
exist.
范例:
redis−>sAdd(‘key1',′set1');redis->sAdd(‘key1′ ,
’set2′);
redis−>sAdd(‘key1',′set3');/∗‘key1'=>′set1',′set2',′set3'∗/redis->sSize(‘key1′); /* 3 */
$redis->sSize(‘keyX’); /* 0
*/

sPop
描述:
随机移除并返回key中的一个值
参数:key
返回值:String
“popped” value        Bool FALSE if set identified by key is empty or doesn’t
exist.
范例:
redis−>sAdd(‘key1',′set1');redis->sAdd(‘key1′ ,
’set2′);
redis−>sAdd(‘key1',′set3');/∗‘key1'=>′set3',′set1',′set2'∗/redis->sPop(‘key1′); /* ’set1′, ‘key1′ => {’set3′, ’set2′}
*/
$redis->sPop(‘key1′); /* ’set3′, ‘key1′ => {’set2′} */

sInter
描述:
返回一个所有指定键的交集。如果只指定一个键,那么这个命令生成这个集合的成员。如果不存在某个键,则返回FALSE。
参数:key1,
key2, keyN: keys identifying the different sets on which we will apply the
intersection.
返回值:Array, contain the result of the intersection between those
keys. If the intersection beteen the different sets is empty, the return value
will be empty array.
范例:
redis−>sAdd(‘key1',‘val1');redis->sAdd(‘key1′, ‘val2′);
redis−>sAdd(‘key1',‘val3');redis->sAdd(‘key1′, ‘val4′);
redis−>sAdd(‘key2',‘val3');redis->sAdd(‘key2′, ‘val4′);
redis−>sAdd(‘key3',‘val3');redis->sAdd(‘key3′,
‘val4′);
var_dump($redis->sInter(‘key1′, ‘key2′,
‘key3′));
输出:
array(2) {[0]=>string(4) “val4″ [1]=>string(4)
“val3″}

sInterStore
描述:
执行sInter命令并把结果储存到新建的变量中。
参数:
Key:
dstkey, the key to store the diff into.
Keys: key1, key2… keyN. key1..keyN
are intersected as in sInter.
返回值:INTEGER: The cardinality of the resulting
set, or FALSE in case of a missing key.
范例:
redis−>sAdd(‘key1',‘val1');redis->sAdd(‘key1′, ‘val2′);
redis−>sAdd(‘key1',‘val3');redis->sAdd(‘key1′, ‘val4′);
redis−>sAdd(‘key2',‘val3');redis->sAdd(‘key2′, ‘val4′);
redis−>sAdd(‘key3',‘val3');redis->sAdd(‘key3′,
‘val4′);
var_dump(redis−>sInterStore(‘output′,‘key1',‘key2',‘key3'));vardump(redis->sMembers(‘output’));
输出:
int(2)
array(2)
{
[0]=>
string(4) “val4″
[1]=>
string(4) “val3″
}

sUnion
描述:
返回一个所有指定键的并集
参数:
Keys: key1,
key2, … , keyN: Any number of keys corresponding to sets in
redis.
返回值:
Array of strings: The union of all these
sets.
范例:
redis−>delete(′s0',′s1',′s2');redis->sAdd(’s0′,
‘1′);
redis−>sAdd(′s0',‘2');redis->sAdd(’s1′,
‘3′);
redis−>sAdd(′s1',‘1');redis->sAdd(’s2′,
‘3′);
redis−>sAdd(′s2',‘4');vardump(redis->sUnion(’s0′, ’s1′,
’s2′));
输出:
array(4) {
[0]=>
string(1)
“3″
[1]=>
string(1) “4″
[2]=>
string(1)
“1″
[3]=>
string(1) “2″
}

sUnionStore
描述:
执行sUnion命令并把结果储存到新建的变量中。
参数:
Key:
dstkey, the key to store the diff into.
Keys: key1, key2, … , keyN: Any
number of keys corresponding to sets in redis.
返回值:
INTEGER: The
cardinality of the resulting set, or FALSE in case of a missing
key.
范例:
redis−>delete(′s0',′s1',′s2');redis->sAdd(’s0′,
‘1′);
redis−>sAdd(′s0',‘2');redis->sAdd(’s1′,
‘3′);
redis−>sAdd(′s1',‘1');redis->sAdd(’s2′,
‘3′);
redis−>sAdd(′s2',‘4');vardump(redis->sUnionStore(‘dst’,
’s0′, ’s1′,
’s2′));
var_dump($redis->sMembers(‘dst’));
输出:
int(4)
array(4)
{
[0]=>
string(1) “3″
[1]=>
string(1)
“4″
[2]=>
string(1) “1″
[3]=>
string(1) “2″
}

sDiff
描述:
返回第一个集合中存在并在其他所有集合中不存在的结果
参数:Keys:
key1, key2, … , keyN: Any number of keys corresponding to sets in
redis.
返回值:Array of strings: The difference of the first set will all the
others.
范例:
redis−>delete(′s0',′s1',′s2');redis->sAdd(’s0′,
‘1′);
redis−>sAdd(′s0',‘2');redis->sAdd(’s0′,
‘3′);
redis−>sAdd(′s0',‘4');redis->sAdd(’s1′,
‘1′);
redis−>sAdd(′s2',‘3');vardump(redis->sDiff(’s0′, ’s1′,
’s2′));
array(2) {
[0]=>
string(1) “4″
[1]=>
string(1)
“2″
}

sDiffStore
描述:
执行sDiff命令并把结果储存到新建的变量中。
参数:
Key:
dstkey, the key to store the diff into.
Keys: key1, key2, … , keyN: Any
number of keys corresponding to sets in redis
返回值:INTEGER: The cardinality of
the resulting set, or FALSE in case of a missing
key.
范例:
redis−>delete(′s0',′s1',′s2');redis->sAdd(’s0′,
‘1′);
redis−>sAdd(′s0',‘2');redis->sAdd(’s0′,
‘3′);
redis−>sAdd(′s0',‘4');redis->sAdd(’s1′,
‘1′);
redis−>sAdd(′s2',‘3');vardump(redis->sDiffStore(‘dst’,
’s0′, ’s1′, ’s2′));
var_dump($redis->sMembers(‘dst’));
Return value:
the number of elements of s0 that are neither in s1 nor in
s2.
int(2)
array(2) {
[0]=>
string(1)
“4″
[1]=>
string(1) “2″
}

sMembers, sGetMembers
描述:
返回集合的内容
参数:Key:
key
返回值:An array of elements, the contents of the
set.
范例:
redis−>delete(′s′);redis->sAdd(’s’,
‘a’);
redis−>sAdd(′s′,‘b′);redis->sAdd(’s’,
‘a’);
redis−>sAdd(′s′,‘c′);vardump(redis->sMembers(’s’));
Output:
array(3)
{
[0]=>
string(1) “c”
[1]=>
string(1)
“a”
[2]=>
string(1) “b”
}

getSet
描述:
返回当前的Key的值,并修改Key为新的值。
参数:
Key:
key
STRING: value
返回值:
A string, the previous value located at this
key.
范例:
redis−>set(‘x′,‘42');exValue = redis−>getSet(‘x′,‘lol′);//return‘42',replacesxby‘lol′newValue = $redis->get(‘x’)’
// return ‘lol’

Redis常用命令(一)的更多相关文章

  1. Redis常用命令

    Redis常用命令Redis提供了丰富的命令对数据库和各种数据类型进行操作,这些命令可以再Linux终端使用.1.键值相关命令2.服务器相关命令 一.键值相关命令 1.get get 键值 当 key ...

  2. 第2讲 Redis常用命令与高级应用

    目录 一.redis数据类型 5. sorted sets类型和操作 二.Redis常用命令 1.键值相关命令 2.服务器相关命令 三. redis高级应用 1. 给redis服务器设置密码 2.持久 ...

  3. Redis常用命令手册:服务器相关命令

    Redis提供了丰富的命令(command)对数据库和各种数据类型进行操作,这些command可以在Linux终端使用.在编程时,比如各类语言包,这些命令都有对应的方法.下面将Redis提供的命令做一 ...

  4. redis redis常用命令及内存分析总结(附RedisClient工具简介

    redis常用命令及内存分析总结(附RedisClient工具简介 by:授客 QQ:1033553122 redis-cli工具 查看帮助 连接redis数据库 常用命令 exists key se ...

  5. Redis常用命令与高级应用

    附: 127.0.0.1:6379> set xiaofei 小飞 OK 127.0.0.1:6379> get xiaofei "\xe5\xb0\x8f\xe9\xa3\x9 ...

  6. Redis快速起步及Redis常用命令大全

    本系列教程内容提要 Java工程师之Redis实战系列教程教程是一个学习教程,是关于Java工程师的Redis知识的实战系列教程,本系列教程均以解决特定问题为目标,使用Redis快速解决在实际生产中的 ...

  7. redis配置密码 redis常用命令

    redis配置密码 1.通过配置文件进行配置yum方式安装的redis配置文件通常在/etc/redis.conf中,打开配置文件找到 [plain] view plain copy   #requi ...

  8. redis常用命令及持久化机制

    redis  常用命令 查找redis服务文件 find / -name  redis-server 查找配置文件 find / -name redis.conf 启动服务时候,要指定配置文件 启动r ...

  9. Redis 常用命令 大全

    Redis 常用命令 发现几个很好的 Redis 常用命令汇总大全网页,分享给小伙伴们~ 1.Redis 命令参考 http://redisdoc.com/string/index.html 2.W3 ...

  10. No-sql之redis常用命令

    转自:http://blog.csdn.net/nicewuranran/article/details/51793760 No-SQL之Redis 介绍 Redis是一种基于内存存储的key-val ...

随机推荐

  1. PowerDesigner连接Oracle数据库生成数据模型【数据源连接方式】

    1.进入操作系统的管理工具 2.选择ODBC数据源[32位或64位] 3.列表中是当前数据库已有的数据源,右侧点击添加按钮,添加适合自己的数据源 4.在列表中选择索要连接数据库的ODBC驱动[这里我要 ...

  2. 【leetcode】Reverse Words in a String

    今天第一次在leetcode上提交了一个题目,据说这个网站基本上都是名企面试笔试题,今天无意一进去就看到第一题居然就是昨天的腾讯实习生笔试题,赶紧注册了个账号做题. 题目描述: Given an in ...

  3. bbed的使用--安装及初探

    bbed是oracle内部一款用来直接查看和修改数据文件数据的工具,可以直接修改Oracle数据文件块的内容,在一些特殊恢复场景下比较有用. 1.bbed 的安装 在9i/10g中连接生成bbed: ...

  4. 咱就入个门之NHibernate映射文件配置(二)

    上一篇主要介绍了NHibernate映射文件的基础配置,这篇我们介绍下NHibernate的一对多及多对一配置(文中我直接使用双向关联,即一和多两端都配置,开发中可以只使用一端),同时略带介绍下NHi ...

  5. Android 大牛的 blog 值得推荐 (转 整理)

    1 收集了 国外著名开发者 25 人,包括 Github 地址.Blog 地址以及重点贡献介绍 链接 收集了 国内部分开发者 32人,包括 Github 地址.Blog 地址以及重点贡献介绍, 链接 ...

  6. Android ImageCache图片缓存,使用简单,支持预取,支持多种缓存算法,支持不同网络类型,扩展性强

    本文主要介绍一个支持图片自动预取.支持多种缓存算法的图片缓存的使用及功能.图片较大需要SD卡保存情况推荐使用ImageSDCardCache. 与Android LruCache相比主要特性:(1). ...

  7. 硬件断点 DrxHook

    硬件断点 DrxHook 硬件断点的实现需要依赖于调试寄存器 DR0~DR7  调试寄存器 DR0~DR3-----调试地址寄存器DR4~DR5-----保留DR6 -----调试状态寄存器 指示哪个 ...

  8. AChartEngine使用View显示图表

    学习过AChartEngine的人肯定都知道,使用ChartFactory创建一张图表可以使用Intent方法,之后调用StartActivity来启用这个Intent,但是这么左右一个坏处,就是当你 ...

  9. eclipse->project->clean…作用

    其实主要作用就是把编译好的class等文件删除,激活eclipse的自动编译.解决的问题就是,有时候你把代码改了,但因为一些未知的原因,eclipse的自动编译没有成功,导致运行结果不正常.当你的工程 ...

  10. css 让内容满屏居中不变形

    .selector { position: fixed; width: 100%; height: 100%; background-image: url(path); background-repe ...