Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Redis data manipulation-- ordered set

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

| Redis collections store multiple different elements in an unordered manner. Users can quickly add or delete elements from the collection, or perform set operations on multiple collections, such as union, intersection and subtraction. | element operation-add element sadd key element [element...] # add one or more elements to a given collection. Elements that already exist in the collection are automatically ignored. The command returns the number of elements newly added to the collection. Remove element srem key element [element...] # removes one or more elements from the collection. Elements that do not exist in the collection are automatically omitted. The command returns the number of elements that exist and are removed. Check whether the given element exists in the collection sismember key element # check whether the given element exists in the collection and return 1 if it exists, or 0 if the element does not exist or the given key does not exist. -- return the size of the collection scard key # returns the number of elements contained in the collection (that is, the cardinality of the collection)-- returns all the elements contained in the collection smember key # Fan Hu collection contains the original elements attached: when the cardinality of the collection is relatively large, executing this command may cause server blocking, and a better way to iterate over the elements in the collection will be introduced in the future. -- the unordered nature of sets # for the same set of elements, the same set command may return different results. Conclusion: do not use collections to store ordered data, use lists if you want to store ordered and repeating values, and use ordered collections if you want to store ordered and non-repeating values. (voting function vote.py), (tagging function tag.py)-- randomly pops an element from the collection spop key # randomly removes and returns an element from the collection-- randomly returns element srandmember key [count] # from the collection if no optional count parameter is given, the command randomly returns an element in the collection. If the count parameter is given, then: ① when count is positive and less than the set cardinality, the command returns an array of count elements, each of which is different; if count is greater than or equal to the set cardinality, the command returns the entire collection. ② when count is negative, the command returns an array, the elements of the array may be repeated multiple times, and the array is frozen to the absolute length of count. # unlike spop, srandmember does not remove returned elements. (implementation of API of lottery program) | set operation-difference operation (in two intersections, it exists in set A. But elements that do not exist in set B) sdiff key [key...] # returns the difference of all given sets sdiffstore destkey key [key...] # stores the difference of a given set into the destkey-- intersection operation sinter key [key...] # returns the intersection sinterstore destkey key of all given sets [key...] # Save the intersection of a given set to destkey-- Union Operation sunion key [key...] # return the union of all given sets sunion key [key...] # Save the union of all given sets into destkey (common concern function) (build product screening function item_filter.py)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report