<?php
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->delete('test');
$redis->sadd("test","111");
$redis->sadd("test","222");
$redis->sadd("test","333");
$redis->sadd("test1","111");
$redis->sadd("test1","444");
print_r($redis->sdiff("test","test1")); //结果:Array ( [0] => 222 [1] => 333 )
?>
29,sdiffstore
描述:执行sdiff命令并把结果储存到新建的变量中。
参数:
Key: dstkey, the key to store the diff into.
Keys: key1, key2, … , keyN: Any number of keys corresponding to sets in redis
返回值:成功返回数字,失败false
范例:
复制代码 代码如下:
<?php
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->delete('test');
$redis->sadd("test","111");
$redis->sadd("test","222");
$redis->sadd("test","333");
$redis->sadd("test1","111");
$redis->sadd("test1","444");
var_dump($redis->sdiffstore('new',"test","test1")); //结果:int(2)
print_r($redis->smembers('new')); //结果:Array ( [0] => 222 [1] => 333 )
?>
30,smembers, sgetmembers
描述:
返回集合的内容
参数:Key: key
返回值:An array of elements, the contents of the set.
范例:
复制代码 代码如下:
<?php
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->delete('test');
$redis->sadd("test","111");
$redis->sadd("test","222");
print_r($redis->smembers('test')); //结果:Array ( [0] => 111 [1] => 222 )
?>
php-redis当中,有很多不同名字,但是功能一样的函数,例如:lrem和lremove,这里就不例举了。
您可能感兴趣的文章: