17. Common operation of SET data
127.0.0.1:6379> sadd set1 1 #向集合set1中放入元素
(integer) 1
127.0.0.1:6379> sadd Set1 2
(integer) 1
127.0.0.1:6379> sadd Set1 3
(integer) 1
127.0.0.1:6379> sadd Set1 4
(integer) 1
127.0.0.1:6379> smembers Set1 #查看集合中所有元素
1) "1"
2) "2"
3) "3"
4) "4"
Srem Set1 1//delete element
127.0.0.1:6379> spop set1 #随机取出一个元素, delete
"Szk"
127.0.0.1:6379> sdiff set1 set2 #比较差集, with Set1 as the main comparison
1) "ZBC"
2) "4"
127.0.0.1:6379> sdiffstore set3 set2 set1 #比较差集, depositing results in Set3
(integer) 2
127.0.0.1:6379> smembers set3 #tab自动补全, but is shown in uppercase
1) "2"
2) "Szk"
sinter Set1 Set2 //Seek intersection
sinterstore set3 Set1 set2 //The intersection is deposited in Set3
sunion Set1 Set2 //Request and set
sunionstore set3 Set1 set2 //Save the Assembly to Set3
sismember Set1 AAA//Determine if an element belongs to a collection
srandmember Set1 //random extraction of an element without deleting
Set data common operations