Redis Collection (SET)

Source: Internet
Author: User

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
  1. Redis 127.0. 0.1:6379> sadd w3ckey redis
  2. (integer) 1
  3. Redis 127.0. 0.1:6379> sadd w3ckey mongodb
  4. (integer) 1
  5. Redis 127.0. 0.1:6379> sadd w3ckey mysql
  6. (integer) 1
  7. Redis 127.0. 0.1:6379> sadd w3ckey mysql
  8. (integer) 0
  9. Redis 127.0. 0.1:6379> smembers w3ckey
  10. 1) "MySQL"
  11. 2) "MongoDB"
  12. 3) "Redis"

In the above example we insert three elements into the collection named W3ckey 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] adds one or more members to the collection
2 SCard Key gets the number of members of the collection
3 Sdiff Key1 [Key2] Returns the difference set for all sets given
4 Sdiffstore destination Key1 [Key2] Returns the difference set for all sets and is stored in destination
5 SINTER Key1 [Key2] returns the intersection of all sets 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 moves the member element from the source collection to the destination collection
10 SPOP key to remove and return a random element from the collection
11 Srandmember key [Count] returns one or more random numbers in the collection
12 Srem key Member1 [member2] removes one or more members from the collection
13 Sunion Key1 [Key2] Returns the set of all the given sets
14 Sunionstore destination Key1 [Key2] The aggregation of all given collections is stored in the destination collection
15 Sscan key cursor [MATCH pattern] [count count] elements in the iteration 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.