Redis Collection (SET)
Redis's set is an unordered collection of type string. A collection member is unique, which means that duplicate data cannot appear in the collection.
The collection in Redis is implemented by a hash table, so the complexity of adding, deleting, and finding is O (1).
The maximum number of members in the collection is 232-1 (4294967295, each of which can store 40多亿个 members).
Instance
Redis127.0.0.1:6379>Sadd Runoobkey Redis(Integer) 1Redis127.0.0.1:6379>Sadd Runoobkey MongoDB(Integer) 1Redis127.0.0.1:6379>Sadd Runoobkey MySQL(Integer) 1Redis127.0. 0.1:6379> Sadd Runoobkey Mysql (integer 0 redis 127.0. 0.1:6379> Smembers Runoobkey 1) "MySQL" 2) "MongoDB" 3) "Redis"
In the above example we insert three elements into the collection named Runoobkey with the sadd command.
Redis Collection Commands
The following table lists the Redis collection basic commands:
Serial Number |
Command and Description |
1 |
Sadd key Member1 [Member2] Add one or more members to a collection |
2 |
SCard Key Gets the number of members of the collection |
3 |
Sdiff Key1 [Key2] Returns the difference set for a given collection of all |
4 |
Sdiffstore destination Key1 [Key2] Returns the difference set for a given collection of all sets and stores it in destination |
5 |
SINTER Key1 [Key2] Returns the intersection of all collections given |
6 |
Sinterstore destination Key1 [Key2] Returns the intersection of all sets given and stored in destination |
7 |
Sismember Key Member Determines whether the member element is a member of the collection key |
8 |
Smembers Key Returns all members in the collection |
9 |
Smove Source Destination Member Move the member element from the source collection to the destination collection |
10 |
SPOP Key Removes and returns a random element in the collection |
11 |
Srandmember key [Count] Returns one or more random numbers in a collection |
12 |
Srem key Member1 [Member2] Remove one or more members from a collection |
13 |
Sunion Key1 [Key2] Returns the set of all the given sets |
14 |
Sunionstore destination Key1 [Key2] The destination of all given collections is stored in the collection |
15 |
Sscan key cursor [MATCH pattern] [count Count] Iterate over elements in a collection |
Redis Collection (SET)