Latest web development tutorials

Redis set (Set)

Redis is an unordered collection of Set string type. It is the only member of the collection, which means that the collection can not duplicate data.

Redis is set by the hash table to achieve, so add, delete, find the complexity is O (1).

Set the maximum number of members 232--1 (4294967295 Each set can store more than 40 million members).

Examples

redis 127.0.0.1:6379> SADD w3bigkey redis
(integer) 1
redis 127.0.0.1:6379> SADD w3bigkey mongodb
(integer) 1
redis 127.0.0.1:6379> SADD w3bigkey mysql
(integer) 1
redis 127.0.0.1:6379> SADD w3bigkey mysql
(integer) 0
redis 127.0.0.1:6379> SMEMBERS w3bigkey

1) "mysql"
2) "mongodb"
3) "redis"

In the example above weSADD command to the collection named w3bigkey insertion of three elements.


Redis command set

The following table lists the Redis set of basic commands:

No. Command and description
1 SADD key member1 [member2]
Add one or more members to the collection
2 SCARD key
Being members of a collection
3 SDIFF key1 [key2]
Returns the difference between the set of all collections
4 SDIFFSTORE destination key1 [key2]
Returns the difference set all set and stored in the destination
5 SINTER key1 [key2]
Back to the intersection of a given set of all
6 SINTERSTORE destination key1 [key2]
Returns the intersection of all sets and stored in the destination
7 SISMEMBER key member
Determining whether the element is a member of a collection of key members
8 SMEMBERS key
Returns a collection of all the members of the
9 SMOVE source destination member
The member elements from source to destination mobile collection set
10 SPOP key
Removes and returns a random element in the collection
11 SRANDMEMBER key [count]
Returns a collection of one or more random number
12 SREM key member1 [member2]
Remove the set of one or more members
13 SUNION key1 [key2]
Back to all given set of union
14 SUNIONSTORE destination key1 [key2]
All the given set and stored in the destination set collection
15 SSCAN key cursor [MATCH pattern] [ COUNT count]
Iterative elements in the collection