Example details of the Redis Set collection

  • 2020-05-17 06:55:16
  • OfStack

Example details of the Redis Set collection

Set of Redis is an unordered collection of type string. Collection members are unique to one, which means that duplicate data cannot occur in the collection.

The collection in redis is implemented by hash table, so the complexity of adding, deleting and searching is O(1).

The largest number of members in a collection is 232-1 (4294967295, each containing more than 4 billion members).

The instance


redis 127.0.0.1:6379> SADD runoobkey redis
(integer) 1
redis 127.0.0.1:6379> SADD runoobkey mongodb
(integer) 1
redis 127.0.0.1:6379> SADD runoobkey mysql
(integer) 1
redis 127.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 example above we used the SADD command to insert three elements into a collection named runoobkey.

Redis collection command

The Redis set of basic commands is listed below:


1  SADD key member1 [member2] 
   Add to the collection 1 One or more members 

2  SCARD key 
   Gets the number of members of a collection 

3  SDIFF key1 [key2] 
   Returns the difference set for a given set 

4  SDIFFSTORE destination key1 [key2] 
   Returns the difference set for a given collection and stores it in  destination  In the 

5  SINTER key1 [key2] 
   Returns the intersection of all sets given 

6  SINTERSTORE destination key1 [key2] 
   Returns the intersection of all the given sets and stores them in  destination  In the 

7  SISMEMBER key member 
   judge  member  Whether elements are collections or not  key  A member of the 

8  SMEMBERS key 
   Returns all members of the collection 

9  SMOVE source destination member 
   will  member  Elements from  source  Set moves to  destination  A collection of 

10 SPOP key 
   Remove and return to the collection 1 X random element 

11 SRANDMEMBER key [count] 
   Go back to the collection 1 Or more random Numbers 

12 SREM key member1 [member2] 
   Remove from the set 1 One or more members 

13 SUNION key1 [key2] 
   Returns the union of all given sets 

14 SUNIONSTORE destination key1 [key2] 
   The union of all given sets is stored in  destination  In the collection 

15 SSCAN key cursor [MATCH pattern] [COUNT count] 
   Iterate over the elements in the set 

The above is the Redis collection of detailed explanation and summary of the collection command, if you have any questions please leave a message or to the site community exchange discussion, thank you for reading, hope to help you, thank you for the support of the site!


Related articles: