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/sscan, http://www.redis.cn/commands/sscan.html
原文:http://www.cnblogs.com/huey/p/4345507.html