set collection
Commonly used commands:
SADD key member [member ...] // to set into the data, if the element is present, the data is ignored; if the key does not exist, then the new
SREM key member [member ...] // delete elements in the collection
SMEMBERS key // get all elements in the collection
SCARD key // Get the number of elements in the set
SISMEMBER key member // determines whether the element is present in the member set in key
SRANDMEMBER key [count] // randomly selected from the set to count elements, the key element is not removed from the
SPOP key [count] // count randomly selected elements from the collection, elements that were removed from key collection
Set arithmetic operations:
SINTER key [key ...] // Communication operation
SINTERSTORE destination key [key ...] // will result intersection operation into a new set of destination in
SUNION key [key ...] // set computing and
SUNIONSTORE destination key [key ...] // the result set and the new set operation into the destination
SDIFF key [key ...] // set difference operation
SDIFFSTORE key [key ...] // set the result of the difference operation into a new set of destination
Scenario:
Sweepstakes applet
1) participate in the lottery: SADD key [userid ...] // key for the active set of users, userid for the user.
2) Check all users to participate in the lottery: SMEMBER key
3) winners were drawn count: SRANDMEMBER / SPOP key [count]