V. Redis BASIC Command---unordered collection

Source: Internet
Author: User

1. Each element in the collection is unique and has no order.
2. Comparison of collections and lists      

Collection List
Store content 2^32-1 up to a string 2^32-1 up to a string
Order of Disordered Ordered
Uniqueness Only Not unique

3, the collection internal use is the value is empty the hash list implementation, therefore inserts, deletes in the collection, determines whether the element existence operation's time complexity is O (1)
4, Sadd key Member1 member2 ... Add elements, you can add multiple
127.0.0.1:6379> sadd SetA 1 2 3 4 (integer) 4

5. smembers key to get all the data127.0.0.1:6379> smembers SetA
1) "1"
2) "2"
3) "3"
4) "4"
6, Srem key value1 value2 Delete data, return the number of deleted127.0.0.1:6379> smembers SetA
1) "1"
2) "2"
3) "3"
4) "4"
127.0.0.1:6379> Srem SetA 1 2
(integer) 2
7, Sismember key member to determine whether there is, return 1 means that there is, return 0 means that does not exist127.0.0.1:6379> smembers SetA
1) "3"
2) "4"
127.0.0.1:6379> sismember SetA 3
(integer) 1
127.0.0.1:6379> sismember SetA 4
(integer) 1127.0.0.1:6379> Sismember SetA 5
(integer) 0
8. Inter-set Operationsdiff key1 key2 Key3 ... Difference SetSINTER key1 key2 Key3 ... Intersectionsunion key1 key2 Key3 ... and set
9, Srandmember Random acquisition of an element           Srandmember Set Count              if the count value is positive, count non-repeating elements are randomly fetched from the collection, and if the count value is greater than the collection size, all elements are returnedif the count value is a negative number, the |count| elements are randomly obtained from the collection, and the elements may be the sameprinciple:The elements returned by Srandmember are not very random, and this occurs because of the storage structure (hash-hash) used by the collection type. The hash table uses a hash function to map elements to different buckets (buckets) to achieve an O (1) time-complexity element lookup. For example, when the hash table stores element B, the hash value of B is 0, and the element b is stored on the number No. 0 bucket. The next get element, the same algorithm is used to calculate the hash value of B is 0, go directly to the number No. 0 bucket to read the element. If an element conflict is encountered, that is, the hash value of more than one element is the same, the collection uses the Zipper method to resolve the conflict, the elements of the hash value conflict are stored in the same bucket as a linked list, find the element when the bucket, and then find the corresponding element in the list. The sandmember command is to randomly fetch a bucket and then randomly fetch an element in the corresponding linked list. So the fewer elements in the bucket where the element is, the more likely it is to be randomly selected. In fact, the principle of HashMap also ibid.           
10. SPOP randomly pops an element from the set
     









     

V. Redis BASE Command---unordered collection

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.