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 common commands (2) list keys, unordered set keys

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

Share

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

# the basic element type of the list key is string, sorted by insertion order

Lpush key value1 value2.. # insert data on the left side of the list

Lpush name dai liu wang

Rpush key value1 value2. # insert data on the right side of the list

Rpush name a b c

Lpop key # removes and returns the leftmost item in the list

Lpop language

Rpop key # removes and returns the item at the far right of the list

Rpop language

In the blocking version of # lpop, the command accesses each given list from left to right, and the leftmost item of the first non-empty list pops up

# if all lists are empty, the client will be blocked until the wait times out or there are popup items.

# 0 means permanent blocking

Blpop key [key...] Timeout

Blpop a100 language 5

Brpop key [key....] Timeout # in contrast to blpop, the command is executed from left to right, popping up the first item at the rightmost end of the non-empty list

Brpop a100 language 5

Llen key # returns the length of the list key key

Llen language

Lindex key index # returns the list item on the specified index index in the list key, which can be positive or negative

Lindex language 0

Linsert key before or after existing element New element # inserts a new element before or after the specified element

Linsert name before a d

Linsert name after an e

Lrange key start stop # returns the elements in the specified range in the list. Start and stop are the subscript indexes of the elements. The index starts on the left, and the first element is 0.

The # index can be negative, indicating that the count starts at the tail, for example,-1 represents the last element

Lrange name 0-1

Lset key index value # sets the list item at the specified index location to value, the index starts on the left, and the first element is 0

The # index can be negative, indicating the start of the tail count, such as-1 for the last element

Lset name 4 zhao

# Delete the specified element and remove the element whose value is value in the previous count occurrence in the list

# count > 0: remove from beginning to end, count

< 0: 从尾往头移除,count = 0: 移除所有 lrem key count value lrem py12 2 h0 # 从py12列表左侧开始删除2个h0 ltrim key start stop # 对列表进行修剪,让列表只保留指定索引范围内的列表项,索引可以是正数或负数 ltrim user::daiby::timeline 0 4 ### set 无序集合,元素为string类型,元素具有唯一性,不重复,说明:对于集合没有修改操作 sadd key member1 member2 ... # 添加元素 sadd py10 aaa bbb ccc aaa -->

(integer) 3

Smembers key # returns all elements, and when the collection is large, this command may cause server blocking

Smembers py10

Srem key member1 member2... # Delete the specified element

Srem py10 aaa

Sismember key member # checks whether the given element exists in the collection

Sismember friends jack

Scard key # returns the number of elements contained in the collection

Scard friends

Spop key # randomly removes from the collection and returns an element

Spop friends

# if no optional count parameter is given, the command randomly returns an element in the collection, which will not be removed

# if count is specified, the number of elements of count is randomly returned from the collection

Srandmember key [count]

Srandmember friends 3

Sdiff key [key...] # calculates the difference of all given sets and returns the result

Sadd num1 111 222 333

Sadd num2 222 333 444

Sdiff num1 num2-- > 111

Sdiffstore destkey key [key...] # calculates the difference of all given sets and stores the results in destkey

Sdiffstore num3 num1 num2

Sinter key [key...] # calculates the intersection of all given sets and returns the result

Sinter num1 num2

Sinterstore destkey key [key...] # calculates the intersection of all given sets and stores the results in destkey

Sinterstore num3 num1 num2

Sunion key [key...] # calculates the union of all given sets and returns the result

Sunion num1 num2

Sunionstore destkey key [key...] # calculates the union of all given collections and stores the results in destkey

Sunionstore num3 num1 num2

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