Redis sets redisコレクション
1672 ワード
Title: Redis sets date: 2015-05-05 12:08:36 +0800 comments: true category: Redis tags: redis,linux
Redis Sets
Redis Sets
## SADD -- add item into set
SADD myset "James"
# if success, return 1, else return 0
## SMEMBERS -- check members in set
SMEMBERS myset
## SREM -- delete members from set
SREM myset "Harry"
# if delete, return 1, else return 0, e.g. delete an un-exist member
## SPOP -- return and delete one key by random in set
SPOP myset
## SDIFF -- key key
SDIFF set1 set2
# return member only in set1 and not in set2
## SDIFFSTORE -- key key , key
SDIFFSTORE result-set set1 set2
SMEMBERS result-set
## SINTER -- key
SINTER set1 set2 [set3 ... setN]
## SINTERSTORE -- set
SINTERSTORE result-set set1 set2 [set3 ... setN]
## SUNION --
SUNION set1 set2 [set3 ... setN]
## SUNIONSTORE -- set
SUNIONSTORE result-set set1 set2 [set3 ... setN]
## SMOVE -- key set member set
SMOVE first-set result-set member-name
127.0.0.1:6379[8]> SMEMBERS t_num2
1) "five"
2) "three"
3) "one"
127.0.0.1:6379[8]> SMOVE t_num2 t_num4 five
(integer) 1
127.0.0.1:6379[8]> SMEMBERS t_num2
1) "three"
2) "one"
127.0.0.1:6379[8]> SMEMBERS t_num4
1) "five"
## SCARD -- return number of the set
SCARD myset
## SINMEMBER -- test if member is in set
SINMEMBER myset member-name
## SRANDMEMBER -- key set ,
SRANDMEMBER myset