- 注册时间
- 2011-3-22
- 最后登录
- 2013-6-27
- 在线时间
- 11644 小时
- 阅读权限
- 150
- 积分
- 62779
- 帖子
- 28923
- 精华
- 1
- UID
- 6
|
sRem, sRemove
删除名称为key的set中的元素value
参数:
key
member
返回值:
Bool
范例:
$redis->sAdd('key1' , 'set1');
$redis->sAdd('key1' , 'set2');
$redis->sAdd('key1' , 'set3'); /* 'key1' => {'set1', 'set2', 'set3'}*/
$redis->sRem('key1', 'set2'); /* 'key1' => {'set1', 'set3'} */
sMove
说明:
将value元素从名称为srckey的集合移到名称为dstkey的集合
参数:
srcKey
dstKey
member
返回值:
Bool 成功返回true 失败返回false
范例:
$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'} */
sIsMember, sContains
说明:
名称为key的集合中查找是否有value元素
参数:
key
value
返回值:
Bool 存在返回true 不存在返回false
范例:
$redis->sAdd('key1' , 'set1');
$redis->sAdd('key1' , 'set2');
$redis->sAdd('key1' , 'set3'); /* 'key1' => {'set1', 'set2', 'set3'}*/
$redis->sIsMember('key1', 'set1'); /* TRUE */
$redis->sIsMember('key1', 'setX'); /* FALSE */
sCard, sSize
说明:
返回名称为key的set的元素个数
参数:
Key
返回值:
Long 元素个数,不存在则返回0
范例:
$redis->sAdd('key1' , 'set1');
$redis->sAdd('key1' , 'set2');
$redis->sAdd('key1' , 'set3'); /* 'key1' => {'set1', 'set2', 'set3'}*/
$redis->sCard('key1'); /* 3 */
$redis->sCard('keyX'); /* 0 */
sPop
说明:
随机返回并删除名称为key的set中一个元素
参数:
key
返回值:
返回被随机取得的值,如果失败返回false
范例:
$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'} */
sRandMember
说明:
随机返回名称为key的set中一个元素
参数:
Key
返回值:
返回的value的值,失败返回false
范例:
$redis->sAdd('key1' , 'set1');
$redis->sAdd('key1' , 'set2');
$redis->sAdd('key1' , 'set3'); /* 'key1' => {'set3', 'set1', 'set2'}*/
$redis->sRandMember('key1'); /* 'set1', 'key1' => {'set3', 'set1', 'set2'} */
$redis->sRandMember('key1'); /* 'set3', 'key1' => {'set3', 'set1', 'set2'} */
sInter
说明:
求交集
参数:
Key1,key2….keyN
返回值:
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'));
Output:
array(2) {
[0]=>
string(4) "val4"
[1]=>
string(4) "val3"
}
sInterStore
说明:
执行sInter命令并把结果储存到新建的变量中。
参数:
Key
Key2:key1,key2…keyN
返回值:
范例:
$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'));
var_dump($redis->sMembers('output'));
Output:
int(2)
array(2) {
[0]=>
string(4) "val4"
[1]=>
string(4) "val3"
}
sUnion
说明:
合并多个key值
参数:
Keys:key1,key2…..keyN
返回值:
这些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');
var_dump($redis->sUnion('s0', 's1', 's2'));
Return value: all elements that are either in s0 or in s1 or in s2.
array(4) {
[0]=>
string(1) "3"
[1]=>
string(1) "4"
[2]=>
string(1) "1"
[3]=>
string(1) "2"
}
sUnionStore
说明:
执行sUnion命令并把结果储存到新建的变量中。
参数:
Key:
Keys:
返回值:
范例:
$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');
var_dump($redis->sUnionStore('dst', 's0', 's1', 's2'));
var_dump($redis->sMembers('dst'));
Return value: the number of elements that are either in s0 or in s1 or in s2.
int(4)
array(4) {
[0]=>
string(1) "3"
[1]=>
string(1) "4"
[2]=>
string(1) "1"
[3]=>
string(1) "2"
}
sDiff
说明:
求差集
参数:
Keys
返回值:
Array
范例:
$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');
var_dump($redis->sDiff('s0', 's1', 's2'));
Return value: all elements of s0 that are neither in s1 nor in s2.
array(2) {
[0]=>
string(1) "4"
[1]=>
string(1) "2"
}
sDiffStore
说明:
求差集并把结果储存到新建的变量中。
参数:
Key
Keys
返回值:
范例:
$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');
var_dump($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的set的所有元素
参数:
Key
返回值:
array
范例:
$redis->delete('s');
$redis->sAdd('s', 'a');
$redis->sAdd('s', 'b');
$redis->sAdd('s', 'a');
$redis->sAdd('s', 'c');
var_dump($redis->sMembers('s'));
Output:
array(3) {
[0]=>
string(1) "c"
[1]=>
string(1) "a"
[2]=>
string(1) "b"
}
getSet
说明:
返回原来key中的值,并将value写入key
参数:
Key
Value
返回值:
这个key的前一个值
范例:
$redis->set('x', '42');
$exValue = $redis->getSet('x', 'lol'); // return '42', replaces x by 'lol'
$newValue = $redis->get('x')' // return 'lol'
randomKey
说明:
随机返回key空间的一个key
参数:
无
返回值:
在redis中随机存在的一个key
范例:
$key = $redis->randomKey();
$surprise = $redis->get($key); // who knows what's in there.
|
|