Redis(五):数据结构之Set常用命令

1.SADD

127.0.0.1:6379> SADD dbset redis memchche mongodb mysql orcal redis 
(integer) 5


2.SMEMBERS 所有成员

127.0.0.1:6379> SMEMBERS dbset
1) "memchche"
2) "mysql"
3) "redis"
4) "mongodb"
5) "orcal"



3.SISMEMBER 判读成员是否存在

127.0.0.1:6379> SISMEMBER dbset sql_server
(integer) 0
127.0.0.1:6379> SISMEMBER dbset mysql
(integer) 1


4.SRANDMEMBER 随机取count个成员

127.0.0.1:6379> SRANDMEMBER dbset 2
1) "mysql"
2) "redis"
127.0.0.1:6379> SRANDMEMBER dbset 2
1) "mysql"
2) "orcal"


5.SPOP 随机删除count个个成员

127.0.0.1:6379> SPOP dbset 1
1) "mysql"


6.SMOVE

127.0.0.1:6379> SMOVE dbset nosqlset redis
(integer) 1
127.0.0.1:6379> SMOVE dbset nosqlset  memchche 
(integer) 1
127.0.0.1:6379> SMOVE dbset nosqlset  mongodb
(integer) 1
127.0.0.1:6379> SMEMBERS dbset
1) "orcal"


7.SREM 移除元素

127.0.0.1:6379> SMEMBERS dbset
1) "mongodb"
2) "sql_server"
3) "mysql"
4) "orcal"
5) "memchche"
6) "redis"
127.0.0.1:6379> SREM dbset sql_server mysql notexit
(integer) 2
127.0.0.1:6379> SMEMBERS dbset
1) "mongodb"
2) "orcal"
3) "memchche"
4) "redis"


8.SCARD 元素的数量

127.0.0.1:6379> SCARD dbset
(integer) 4


9.SDIFF key1中元素 不存在 key2中的

127.0.0.1:6379> SMEMBERS dbset
1) "mongodb"
2) "orcal"
3) "memchche"
4) "redis"
127.0.0.1:6379> SMEMBERS nosqlset
1) "mongodb"
2) "memchche"
3) "redis"
127.0.0.1:6379> SDIFF dbset nosqlset 
1) "orcal"
127.0.0.1:6379> SDIFF nosqlset dbset
(empty list or set)


10.SDIFFSTORE 取set1和set2中相同的然后覆盖set1(set1 - (sdiff set1 set2))

127.0.0.1:6379> SDIFF dbset nosqlset
1) "orcl"
2) "sql-server"
3) "mysql"
127.0.0.1:6379> SDIFFstore dbset nosqlset
(integer) 3
127.0.0.1:6379> SMEMBERS dbset
1) "mongodb"
2) "memchche"
3) "redis"


11.SINTER 交集

127.0.0.1:6379> SMEMBERS dbset
1) "mongodb"
2) "memchche"
3) "mysql"
4) "redis"
5) "orcl"
127.0.0.1:6379> SMEMBERS nosqlset
1) "mongodb"
2) "memchche"
3) "redis"
127.0.0.1:6379> SINTER dbset nosqlset
1) "mongodb"
2) "memchche"
3) "redis"


12.SINTERSTORE

127.0.0.1:6379> SMEMBERS dbset
1) "mongodb"
2) "memchche"
3) "mysql"
4) "redis"
5) "orcl"
127.0.0.1:6379> SMEMBERS nosqlset
1) "mongodb"
2) "memchche"
3) "redis"
127.0.0.1:6379> SINTERSTORE dbset nosqlset 
(integer) 3
127.0.0.1:6379> SMEMBERS dbset
1) "mongodb"
2) "memchche"
3) "redis"


13.SUNION

127.0.0.1:6379> SUNION nosqlset sqlset
1) "mongodb"
2) "memchche"
3) "redis"
4) "mysql"
5) "orcl"
6) "sql-server"


14.SUNIONSTORE
 

127.0.0.1:6379> SMEMBERS nosqlset
1) "orcl"
2) "sql-server"
3) "mysql"

 

你可能感兴趣的:(数据库,Redis)