集合set :
元素不重复,无序,一个集合可以存2^32-1个元素
set 操作:增删改查,交集,并集,差集
// 增 : sadd key element [ element1 ... ]
// 删 : srem key element [ element1 ... ]
// 计算个数 : scard key
// 元素是否在集合中 : sismember key element
// 随机从集合中返回指定个数元素 : srandmember key [count] count默认1 集合元素个数不变
// 从集合中随机弹出元素 : spop key [count] 集合元素个数减少count个
// 获取所有元素 : smembers key
$k31 = 'imei:set:test1';
$redis->del($k31);
$redis->sadd($k31, '1', '2', '3', '4', '5', '6');
// print_r($redis->smembers($k31));// ['1', '2', '3', '4', '5', '6']
$redis->srem($k31, '1', '2');
//print_r($redis->smembers($k31));// ['3', '4', '5', '6']
$redis->scard($k31);// 4
var_dump($redis->sismember($k31, 1));// string(1) "0"
var_dump($redis->sismember($k31, 4));// string(1) "1"
print_r($redis->srandmember($k31, 2));// [6,4]
print_r($redis->spop($k31, 2));// [5,3]
$k31 = 'imei:set:test1';
$k32 = 'imei:set:test2';
$k33 = 'imei:set:test3';
$k34 = 'imei:set:test4';
$k35 = 'imei:set:test5';
$redis->del($k31);
$redis->del($k32);
$redis->del($k33);
$redis->del($k34);
$redis->del($k35);
$redis->sadd($k31, '1', '2', '3', '4', '5', '6');
$redis->sadd($k32, 'a', 'b', 'c', 'd', '5', '6');
var_dump($redis->sinterstore($k33, $k31, $k32));// string(1) "2"
print_r($redis->smembers($k33));// [ '5', '6']
var_dump($redis->sunionstore($k34, $k31, $k32));// string(1) "10"
print_r($redis->smembers($k34));// Array ( [0] => 5 [1] => 4 [2] => 1 [3] => 2 [4] => 6 [5] => a [6] => 3 [7] => b [8] => d [9] => c )
var_dump($redis->sdiffstore($k35, $k31, $k32));// string(1) "4"
print_r($redis->smembers($k35));// Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 )