当前位置:网站首页>Redis: operation commands for list type data
Redis: operation commands for list type data
2022-07-03 17:00:00 【dengfengling999】
list (List)
Redis List is a simple list of strings , Sort by insertion order , On the left ( Head )、 On the right ( The tail ) Or you can add elements in the middle . The operation of linked list, whether head or tail, is very efficient , But if you operate on intermediate elements , Then the efficiency will be greatly reduced .
The general idea of list type data operation is through key And subscript operations value,key It's a data ID , The subscript is the position of the data in the list ,value This is the business data we are interested in .
1.lpush
grammar :lpush key value [value…]
function : Put one or more values value Insert into list key On the far left of ( Header ), each value Values are inserted into the header position in turn .
Return value : The length of the inserted list .
for example :
2.lrange
grammar :lrange key startIndex endIndex
function : To obtain a list of key Specifies the elements within the subscript interval in , Subscript from 0 Start , Length to list -1; The subscript can also be negative , Indicates that the list is taken from the back to the front ,-1 Represents the last but one element ,-2 That's the penultimate element , And so on ;startIndex and endIndex Out of range, no error will be reported .
Return value : Get the list of elements .
for example : obtain list01 1 To 2 The elements of :
3.rpush
grammar :rpush key value [value…]
function : Put one or more values value Insert into list key On the far right of ( Tail ), each value Values are inserted at the end of the table in order .
Return value : The length of the inserted list .
for example : Put it at the end of the table One time :abcde
Reuse lpush Deposit m and n
4.lpop
grammar :lpop key
function : Remove and return to list key The first element of the head , The first element on the left side of the list .
Return value : The value of the first element on the left side of the list ; list key non-existent , return nil.
for example :
5.rpop
grammar :rpop key
function : Remove and return to list key The first element in the tail , The first element on the right side of the list .
Return value : The value of the first element on the right side of the list ; list key non-existent , return nil.
for example :
6.lindex
grammar :lindex key index
function : To obtain a list of key The subscript indicates index The elements of , List elements are not deleted , Just search .0 Represents the first element of the list ,1 Represents the second element of the list ;index You can also subscript negative numbers , -1 Represents the last element of the list , -2 Represents the penultimate element of a list , And so on .
Return value :key In existence , Returns the value of the specified element ;
Key When there is no , return nil.
for example : Gets the specified subscript :
7.llen
grammar :llen key
function : To obtain a list of key The length of
Return value : The number , The length of the list ;key There is no return 0
for example :
8.lrem
grammar :lrem key count value
function : According to the parameters count Value , Remove the list and parameters value Equal elements ,
count >0 , Remove from the left side of the list to the right ;
count < 0 Remove from the end of the list ;
count = 0 Remove all and from the table value Equal value .
Return value : The number , Number of elements removed
for example :count=2
count=-1
count=0
9.ltrim
grammar :ltrim key startIndex endIndex
function : Intercept key The element of the specified subscript interval , And assigned to key. Subscript from 0 Start , Up to the length of the list -1; The subscript can also be negative , Indicates that the list is taken from the back to the front ,-1 Represents the last but one element ,-2 That's the penultimate element , And so on ;startIndex and endIndex Out of range, no error will be reported .
Return value : Execution successful return ok
10.lset
grammar :lset key index value
function : Will list key Subscript to be index The value of the element of is set to value.
function : Set successfully returned ok ; key Nonexistence or index Out of range return error message .
11.linsert
grammar :linsert key before/after pivot value
function : Will value value Insert into list key Middle value pivot Before or after .key Nonexistence or pivot Not in the list , Do nothing .
Return value : Command executed successfully , Returns the length of the new list . Can't find pivot return -1, key There is no return 0.
边栏推荐
- 免费数据 | 新库上线 | CnOpenData中国保险中介机构网点全集数据
- One brush 142 monotone stack next larger element II (m)
- 线程池:业务代码最常用也最容易犯错的组件
- On Lagrange interpolation and its application
- Hands on in-depth learning notes (XIV) 3.7 Simple implementation of softmax regression
- CC2530 common registers for serial communication
- 网络安全web渗透技术
- Arduino esp32: overall framework of lvgl project (I)
- Why is WPA3 security of enterprise business so important?
- visual studio “通常每个套接字地址(协议/网络地址/端口)只允许使用一次“
猜你喜欢
One brush 149 force deduction hot question-10 regular expression matching (H)
NLP四范式:范式一:非神经网络时代的完全监督学习(特征工程);范式二:基于神经网络的完全监督学习(架构工程);范式三:预训练,精调范式(目标工程);范式四:预训练,提示,预测范式(Prompt工程)
線程池:業務代碼最常用也最容易犯錯的組件
静态程序分析(一)—— 大纲思维导图与内容介绍
ucore概述
Pools de Threads: les composants les plus courants et les plus sujets aux erreurs du Code d'affaires
utfwry. Dat PHP, about ThinkPHP's method of IP location using utfwry address Library
Kotlin learning quick start (7) -- wonderful use of expansion
What is your income level in the country?
What material is sa537cl1? Sa537cl1 corresponds to the national standard material
随机推荐
New features of C 10
[combinatorics] recursive equation (the relationship theorem between the solution of the recursive equation and the characteristic root | the linear property theorem of the solution of the recursive e
[Jianzhi offer] 57 - ii Continuous positive sequence with sum s
Mysql database DDL and DML
What kind of material is 14Cr1MoR? Analysis of chemical composition and mechanical properties of 14Cr1MoR
Pools de Threads: les composants les plus courants et les plus sujets aux erreurs du Code d'affaires
PHP online confusion encryption tutorial sharing + basically no solution
人生还在迷茫?也许这些订阅号里有你需要的答案!
What is the material of sa302grc? American standard container plate sa302grc chemical composition
What material is 13crmo4-5 equivalent to in China? 13crmo4-5 chemical composition 13crmo4-5 mechanical properties
Meituan side: why does thread crash not cause JVM crash
[mathematical logic] equivalent calculus and reasoning calculus of propositional logic (propositional logic | equivalent calculus | principal conjunctive (disjunctive) paradigm | reasoning calculus)**
RedHat 6.2 配置 Zabbix
CC2530 common registers for port interrupts
[Jianzhi offer] 64 Find 1+2+... +n
线程池:业务代码最常用也最容易犯错的组件
What material is sa537cl2 equivalent to in China? Sa537cl2 corresponding material
NLP four paradigms: paradigm 1: fully supervised learning in the era of non neural networks (Feature Engineering); Paradigm 2: fully supervised learning based on neural network (Architecture Engineeri
Define a structure fraction to represent a fraction, which is used to represent fractions such as 2/3 and 5/6
Visual studio "usually, each socket address (Protocol / network address / port) can only be used once“