Redis Collection (SET)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.