首页 > 其他 > 详细

Redis(2.8.3) 命令学习 - Sets

时间:2015-09-25 11:02:04      阅读:199      评论:0      收藏:0      [点我收藏+]

SADD key member [member ...]

Add one or more members to a set

127.0.0.1:6379> SADD foo hello
(integer) 1
127.0.0.1:6379> SADD foo world
(integer) 1
127.0.0.1:6379> SADD foo hello
(integer) 0
127.0.0.1:6379> SMEMBERS foo
1) "world"
2) "hello"

 

SCARD key

Get the number of members in a set

127.0.0.1:6379> SADD foo hello world
(integer) 2
127.0.0.1:6379> SMEMBERS foo
1) "world"
2) "hello"
127.0.0.1:6379> SCARD foo
(integer) 2
127.0.0.1:6379> SMEMBERS none
(empty list or set)
127.0.0.1:6379> SCARD none
(integer) 0

 

SDIFF key [key ...]

Subtract multiple sets

127.0.0.1:6379> SMEMBERS foo
1) "world"
2) "hello"
127.0.0.1:6379> SMEMBERS bar
1) "hello"
2) "redis"
127.0.0.1:6379> SDIFF foo bar
1) "world"

 

SDIFFSTORE destination key [key ...]

Subtract multiple sets and store the resulting set in a key

127.0.0.1:6379> SMEMBERS foo
1) "world"
2) "hello"
127.0.0.1:6379> SMEMBERS bar
1) "hello"
2) "redis"
127.0.0.1:6379> SDIFFSTORE result foo bar
(integer) 1
127.0.0.1:6379> SMEMBERS result
1) "world"

 

SINTER key [key ...]

Intersect multiple sets

127.0.0.1:6379> SMEMBERS foo
1) "world"
2) "hello"
127.0.0.1:6379> SMEMBERS bar
1) "hello"
2) "redis"
127.0.0.1:6379> SINTER foo bar
1) "hello"

 

SINTERSTORE destination key [key ...]

Intersect multiple sets and store the resulting set in a key

127.0.0.1:6379> SMEMBERS foo
1) "world"
2) "hello"
127.0.0.1:6379> SMEMBERS bar
1) "hello"
2) "redis"
127.0.0.1:6379> SINTERSTORE result foo bar
(integer) 1
127.0.0.1:6379> SMEMBERS result
1) "hello"

 

SISMEMBER key member

Determine if a given value is a member of a set

127.0.0.1:6379> SMEMBERS foo
1) "world"
2) "hello"
127.0.0.1:6379> SISMEMBER foo world
(integer) 1
127.0.0.1:6379> SISMEMBER foo redis
(integer) 0

 

SMEMBERS key

Get all the members in a set

127.0.0.1:6379> SADD foo hello
(integer) 1
127.0.0.1:6379> SADD foo world
(integer) 1
127.0.0.1:6379> SMEMBERS foo
1) "world"
2) "hello"

 

SMOVE source destination member

Move a member from one set to another

127.0.0.1:6379> SMEMBERS foo
1) "world"
2) "hello"
127.0.0.1:6379> SMEMBERS bar
1) "hello"
2) "redis"
127.0.0.1:6379> SMOVE foo bar world
(integer) 1
127.0.0.1:6379> SMEMBERS foo
1) "hello"
127.0.0.1:6379> SMEMBERS bar
1) "world"
2) "hello"
3) "redis"

 

SPOP key [count]

Remove and return one or multiple random members from a set

127.0.0.1:6379> SADD foo a b c d e
(integer) 5
127.0.0.1:6379> SPOP foo
"b"
127.0.0.1:6379> SMEMBERS foo
1) "d"
2) "a"
3) "c"
4) "e"
127.0.0.1:6379> SPOP foo
"a"
127.0.0.1:6379> SMEMBERS foo
1) "d"
2) "c"
3) "e"

 

SRANDMEMBER key [count]

Get one or multiple random members from a set

127.0.0.1:6379> SADD foo a b c d
(integer) 4
127.0.0.1:6379> SRANDMEMBER foo
"b"
127.0.0.1:6379> SRANDMEMBER foo
"a"

 

SREM key member [member ...]

Remove one or more members from a set

127.0.0.1:6379> SMEMBERS foo
1) "world"
2) "hello"
127.0.0.1:6379> SREM foo world
(integer) 1
127.0.0.1:6379> SMEMBERS foo
1) "hello"

 

SUNION key [key ...]

Add multiple sets

127.0.0.1:6379> SMEMBERS foo
1) "world"
2) "hello"
127.0.0.1:6379> SMEMBERS bar
1) "hello"
2) "redis"
127.0.0.1:6379> SUNION foo bar
1) "hello"
2) "world"
3) "redis"

 

SUNIONSTORE destination key [key ...]

Add multiple sets and store the resulting set in a key

127.0.0.1:6379> SMEMBERS foo
1) "world"
2) "hello"
127.0.0.1:6379> SMEMBERS bar
1) "hello"
2) "redis"
127.0.0.1:6379> SUNIONSTORE result foo bar
(integer) 3
127.0.0.1:6379> SMEMBERS result
1) "hello"
2) "world"
3) "redis"

 

SSCAN key cursor [MATCH pattern] [COUNT count]

Incrementally iterate Set elements

More: http://redis.io/commands/sscanhttp://www.redis.cn/commands/sscan.html

 

Redis(2.8.3) 命令学习 - Sets

原文:http://www.cnblogs.com/huey/p/4345507.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!