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

Sets type and operation of redis

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

Sets type and operation

Set is a set, which is similar to the concept of set in our mathematics. There are operations such as adding and deleting elements to the set, intersecting and subtracting multiple sets, and so on. Key is understood as the name of the set.

Set is implemented through hash table (that is, set is not ordered), so the complexity of adding, deleting, and searching is O (1). Hash table automatically resizes as it is added or removed. It is important to note that synchronizing (acquiring write locks) when adjusting hash table will block other read and write operations, and may soon switch to skip list, which is already used in sorted set. In addition to the basic add and delete operations on set collection types, other useful operations include union, intersection, and difference of collections. Through these operations, you can easily implement the friend recommendation in sns and the tag function of blog.

Sadd

Adds the specified element to the collection set.

Such as: sadd myset "hello"

Srem

Delete the specified element in the set

Such as: srem myset "hello"

Spop

Randomly delete elements in set and return this data

Sdiff

Returns elements that set1 does not have in set2.

Such as: sdiff set1 set2

Sdiffstore

Returns elements that set1 does not have in set2 and stores them in another set.

Such as: sdiff set1 set2 set3

Smembers

View Set elements

Such as: smembers set1

Sinter

Returns the intersection of the specified set (multiple)

Such as: sinter set1 set2 set3

Sinterstore

Returns the intersection of the specified set and saves it as another set.

Sunion

Returns the union of all given set

Such as: sunion set1 set2 set3

Sunionstore

Returns the union of all given set and stores it as another set

Smove

Remove the member from the first set and add it to the second corresponding set

Such as: smove myset2 myset7 member

Scard

Returns the number of elements of set

Sismember

Test whether member is an element of set

Srandmember

Randomly returns an element of set, but does not delete the element

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