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

Lists 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--

Lists type and operation

List is a linked list structure, and its main functions are push, pop, getting all values in a range, and so on. Key is understood as the name of the linked list in the operation.

The list type of Redis is actually a two-way linked list with each child element of type string. The maximum length of the linked list is (2 to the 32). We can add and remove elements from the head or tail of the linked list through the push,pop operation. This allows list to be used as both a stack and a queue.

What is interesting is that there is also a blocking version of list's pop operation. When we [lr] pop a list object, if list is empty or does not exist, we will immediately return nil. But the blocking version of b[ LR] pop can block, of course, you can add a timeout, and a nil will be returned after the timeout. Why block the version of pop, mainly to avoid polling. Let's take a simple example if we use list to implement a work queue. The thread that executes the task can call the blocking version of pop to get the task so that polling can be avoided to check for the existence of the task. When the task comes, the worker thread can return immediately, or it can avoid the delay caused by polling.

Lpush

Add a string element to the header of the corresponding list of key

Such as: lpush mylist "aaa"bbb"

Rpush

Add a string element to the tail of the corresponding list of key

Linsert

Add string elements before or after the specific position of the key corresponding to the list

Such as: linsert mylist3 before "world"there"

Lset

Sets the element value of the specified subscript in the list (subscript starts at 0)

Such as lset mylist4 0 "four"

Lrem

Delete count elements that are the same as value from the corresponding list of key.

When count > 0, delete it from beginning to end

Count

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