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
keydoes 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
keydoes 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
keydoes 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
memberfrom set. - Return: 1 if remove successful, 0 if
memberorkeydoes not exist.
SMOVE¶
- Syntax:
SMOVE source destination member - Description: Moves the
memberfromsourcetodestination. Thesourceanddestinationrequired same type. - Return: 1 if move successful, 0 if
sourceordestinationormemberdoes not exist.
SISMEMBER¶
- Syntax:
SISMEMBER key member - Description: Returns whether
memberis a member of the set. - Return:
- 1 if the
memberis a member of set. - 0 if the
memberis not a number of set. - 0 if
keydoes not exist.
- 1 if the
Set operations¶
SINTER¶
- Syntax:
SINTER key1 [key2 ...] - Description: Intersects set
key1and others set. - Return:
- All members that exist in both sets.
- (empty array) if any key does not exits.
- All members of
key1if only givenkey1
SUNION¶
- Syntax:
SUNION key1 [key2 ...] - Description: Combines set
key1and others set. - Return:
- All members of all sets but not duplicated.
- (empty array) if any key does not exits.
- All members of
key1if 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
key1if only givenkey1
- All member that only exist in set
SINTERSTORE¶
- Syntax:
SINTERSTORE destination key1 [key2 ...] - Description: Intersect sset
key1and others set, than store the result into a new setdestination. You can modify the set by specifyingdestinationas one of the keys. - Return:
- All members that exist in both sets.
- (empty array) if any key does not exits.
- All members of
key1if only givenkey1
SUNIONSTORE¶
- Syntax:
SUNIONSTORE destination key1 [key2 ...] - Description: Combines set
key1and others set, than store the result into a new setdestination. You can modify the set by specifyingdestinationas one of the keys. - Return:
- All members of all sets but not duplicated.
- (empty array) if any key does not exits.
- All members of
key1if 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 specifyingdestinationas one of the keys. - Return:
- All member that only exist in set
key1. - (empty array) if any key does not exits.
- All members of
key1if only givenkey1
- All member that only exist in set