Redis Learning Note (v)-set type of data type

Source: Internet
Author: User

  Redis's set is an unordered collection of type string. The set element can contain a maximum of (2 of 32 square-1) elements. The set is implemented by hash table, so the complexity of adding, deleting, and finding is O (1). The hash table is automatically resized as it is added or removed. It is important to note that when adjusting the hash table size, synchronization (acquisition of write locks) is required to block other read and write operations. It is possible that a skip list will be used instead of a jump table, which is already in use in sorted set. For the Set collection type in addition to the basic add-delete operation, other useful operations include the collection's union, intersection (intersection), and difference set (difference). Through these actions can easily realize the SNS in the Friend referral and blog tag function.

  Set related commands:

Sadd Key member adds a string element to the set set that corresponds to key, successfully returns 1 if the element has returned 0 in the collection

  scard Key Returns the number of elements of set, if set is empty or key does not exist return 0

  smembers Key Returns all elements of the set corresponding to the key, the result is unordered

  Sismember Key member determine if member is in set, there is a return 1,0 that does not exist or key does not exist

  Srandmember key with Spop, randomly takes an element in set, but does not delete the element

  

  spop key deletes and returns the key corresponding to a random element in set, if set is empty or key does not exist return nil

  Srem Key member removes the given element from the key corresponding set, returns 1 successfully, if the member does not exist in the collection or the key does not exist return 0

  

  Smove srckey Dstkey member remove the member from the Srckey corresponding set and add it to the dstkey corresponding set, the entire operation is atomic. Successful return 1 if member does not exist in Srckey returns 0 if key is not a set type return error

  

  

Redis Learning Note (v)-set type of data type

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.