Type: Set¶
Set is an disorderly, unrepeatable, random type.
The key words of type Set are Random and Disorder. So it is suitable for raffle
scenarios.
It has some manipualtion:
manipualtion | command |
---|---|
set | SADD |
get | SPOP, SRANDMEMBER |
list | SMEMBERS |
length | SCARD |
delete | SREM |
move | SMOVE |
check | SISMEMBER |
operate | SDIFF, SINTER, SUNION |
SADD¶
- Syntax:
SADD key member [member ...]
- Description: Adds a member into set which named
key
. The set will be created if it does not exist. - Return: Number of successful added.
SMEMBERS¶
- Syntax:
SMEMBERS key
- Description: Lists all members of set named
key
- Return: All members of set, (empty array) if
key
does not exist.
SCARD¶
- Syntax:
SCARD key
- Description: Returns the number of members in the set named
key
. - Return: Numbers of set's count, 0 if
key
does not exist.
SPOP¶
- Syntax:
SPOP key [count]
- Description: Gets and remove a member randomly from set named
key
. - Return: Members of set.
- If count is specified, return count member.
- If count greater than or equal to
(>=)
actual number of set's members, it will return all members and clear them. - Nil if
key
does not exist.
SRANDMEMBER¶
- Syntax:
SRANDMEMBER key [count]
- Description: Gets a member randomly from set named
key
. This will not remove any members. - Return: Members of set.
- If count is specified, return count member.
- If count greater than or equal to
(>=)
actual number of set's members, it will return all members. - Nil if key does not exist.
SREM¶
- Syntax:
SREM key member [member ...]
- Description: Removes the
member
from set. - Return: 1 if remove successful, 0 if
member
orkey
does not exist.
SMOVE¶
- Syntax:
SMOVE source destination member
- Description: Moves the
member
fromsource
todestination
. Thesource
anddestination
required same type. - Return: 1 if move successful, 0 if
source
ordestination
ormember
does not exist.
SISMEMBER¶
- Syntax:
SISMEMBER key member
- Description: Returns whether
member
is a member of the set. - Return:
- 1 if the
member
is a member of set. - 0 if the
member
is not a number of set. - 0 if
key
does not exist.
- 1 if the
Set operations¶
SINTER¶
- Syntax:
SINTER key1 [key2 ...]
- Description: Intersects set
key1
and others set. - Return:
- All members that exist in both sets.
- (empty array) if any key does not exits.
- All members of
key1
if only givenkey1
SUNION¶
- Syntax:
SUNION key1 [key2 ...]
- Description: Combines set
key1
and others set. - Return:
- All members of all sets but not duplicated.
- (empty array) if any key does not exits.
- All members of
key1
if only givenkey1
SDIFF¶
- Syntax:
SDIFF key1 [key2 ...]
- Description: Subtracts others set from set
key1
. - Return:
- All member that only exist in set
key1
. - (empty array) if any key does not exits.
- All members of
key1
if only givenkey1
- All member that only exist in set
SINTERSTORE¶
- Syntax:
SINTERSTORE destination key1 [key2 ...]
- Description: Intersect sset
key1
and others set, than store the result into a new setdestination
. You can modify the set by specifyingdestination
as one of the keys. - Return:
- All members that exist in both sets.
- (empty array) if any key does not exits.
- All members of
key1
if only givenkey1
SUNIONSTORE¶
- Syntax:
SUNIONSTORE destination key1 [key2 ...]
- Description: Combines set
key1
and others set, than store the result into a new setdestination
. You can modify the set by specifyingdestination
as one of the keys. - Return:
- All members of all sets but not duplicated.
- (empty array) if any key does not exits.
- All members of
key1
if only givenkey1
SDIFFSTORE¶
- Syntax:
SDIFFSTORE destination key1 [key2 ...]
- Description: Subtracts others set from set
key1
, than store the result into a new setdestination
. You can modify the set by specifyingdestination
as one of the keys. - Return:
- All member that only exist in set
key1
. - (empty array) if any key does not exits.
- All members of
key1
if only givenkey1
- All member that only exist in set