Redis 命令 - Sets

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"

More: http://redis.io/commands/saddhttp://www.redis.cn/commands/sadd.html

 

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

More: http://redis.io/commands/scardhttp://www.redis.cn/commands/scard.html

 

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"

More: http://redis.io/commands/sdiffhttp://www.redis.cn/commands/sdiff.html

 

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"

More: http://redis.io/commands/sdiffstorehttp://www.redis.cn/commands/sdiffstore.html

 

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"

More: http://redis.io/commands/sinterhttp://www.redis.cn/commands/sinter.html

 

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"

More: http://redis.io/commands/sinterstorehttp://www.redis.cn/commands/sinterstore.html

 

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

More: http://redis.io/commands/sismemberhttp://www.redis.cn/commands/sismember.html

 

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"

More: http://redis.io/commands/smembershttp://www.redis.cn/commands/smembers.html

 

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"

More: http://redis.io/commands/smovehttp://www.redis.cn/commands/smove.html

 

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"

More: http://redis.io/commands/spophttp://www.redis.cn/commands/spop.html

 

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"

More: http://redis.io/commands/srandmemberhttp://www.redis.cn/commands/srandmember.html

 

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"

More: http://redis.io/commands/sremhttp://www.redis.cn/commands/srem.html

 

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"

More: http://redis.io/commands/sunionhttp://www.redis.cn/commands/sunion.html

 

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"

More: http://redis.io/commands/sunionstorehttp://www.redis.cn/commands/sunionstore.html

 

SSCAN key cursor [MATCH pattern] [COUNT count]

Incrementally iterate Set elements

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

 

posted on 2015-09-25 09:56  huey2672  阅读(401)  评论(0编辑  收藏  举报