03.Set相关命令


SADD key member [member ...]
SREM key member [member ...]

SISMEMBER key member
SMISMEMBER key member [member ...]

SCARD key
SMEMBERS key
SCAN key cursor [MATCH pattern] [COUNT count]

SMOVE source destination member
SPOP key [count]
SRANDMEMBER key [count]

# 集合操作
SUNION key [key ...]
SUNIONSTORE destination key [key ...]
SINTER key [key ...]
SINTERSTORE destination key [key ...]
SDIFF key [key ...]
SDIFFSTORE destination key [key ...]
SINTERCARD numkeys key [key ...] [LIMIT limit]

数据结构

Set数据结构是Dict字典,字典使用哈希表实现的。Java中的HashSet的内部实现使用的是HashMap,只不过所有的Value都指向了同一个对象。Redis的Set结构也是一样的,它的内部也使用Hash结构,所有的value都指向同一个内部值。

参考资料

  1. Redis#Set