当前位置:网站首页>Redis basic data type (list)
Redis basic data type (list)
2022-06-11 21:26:00 【Don't like learning since childhood~】
Redis Basic data type (List)
stay Redis in , We can list Play into Stack 、 queue 、 Blocking queues !
be-all list Commands are L At the beginning ,Redis Case insensitive commands
127.0.0.1:6379> flushall
OK
127.0.0.1:6379> keys *
(empty array)
127.0.0.1:6379> LPUSH list one # Put one or more values , Insert to the head of the list ( Left )
(integer) 1
127.0.0.1:6379> LPUSH list two
(integer) 2
127.0.0.1:6379> LPUSH list three
(integer) 3
127.0.0.1:6379> LRANGE list 0 -1 # obtain list The value in
1) "three"
2) "two"
3) "one"
127.0.0.1:6379> LRANGE list 0 1 # Get specific values through intervals
1) "three"
2) "two"
127.0.0.1:6379> RPUSH list righr # # Put one or more values , Insert to the head of the list ( Right )
(integer) 4
127.0.0.1:6379> LRANGE list 0 1
1) "three"
2) "two"
127.0.0.1:6379> LRANGE list 0 -1
1) "three"
2) "two"
3) "one"
4) "righr"
########################################################
LPOP
RPOP
127.0.0.1:6379> LPOP list # Remove the first element of the list
"three"
127.0.0.1:6379> RPOP list # Remove the last element of the list
"righr"
127.0.0.1:6379> LRANGE list 0 -1
1) "two"
2) "one"
########################################################
LINDEX
127.0.0.1:6379> LRANGE list 0 -1
1) "two"
2) "one"
127.0.0.1:6379> LINDEX list 1 # Get... By subscript list One of the values
"one"
127.0.0.1:6379> LINDEX list 0
"two"
########################################################
LLEN
127.0.0.1:6379> flushdb
OK
127.0.0.1:6379> LPUSH list one
(integer) 1
127.0.0.1:6379> LPUSH list two
(integer) 2
127.0.0.1:6379> LPUSH list three
(integer) 3
127.0.0.1:6379> LLEN list # Returns the length of the list
(integer) 3
########################################################
Remove the specified value !
Take off uid
127.0.0.1:6379> LPUSH list three
(integer) 4
127.0.0.1:6379> LRANGE list 0 -1
1) "three"
2) "three"
3) "two"
4) "one"
127.0.0.1:6379> LREM list 1 one # remove list Of a specified number in a set value, Exactly match
(integer) 1
127.0.0.1:6379> LRANGE list 0 -1
1) "three"
2) "three"
3) "two"
127.0.0.1:6379> LREM list 1 three
(integer) 1
127.0.0.1:6379> LRANGE list 0 -1
1) "three"
2) "two"
127.0.0.1:6379> LPUSH list three
(integer) 3
127.0.0.1:6379> LREM list 2 three
(integer) 2
127.0.0.1:6379> LRANGE list 0 -1
1) "two"
########################################################
trim trim :list truncation !
127.0.0.1:6379> RPUSH mylist "hello"
(integer) 1
127.0.0.1:6379> RPUSH mylist "hello1"
(integer) 2
127.0.0.1:6379> RPUSH mylist "hello2"
(integer) 3
127.0.0.1:6379> RPUSH mylist "hello3"
(integer) 4
127.0.0.1:6379> LTRIM mylist 1 2 # Intercept the specified length by subscript , This list Has been changed , Only the intercepted elements are left
OK
127.0.0.1:6379> LRANGE mylist 0 -1
1) "hello1"
2) "hello2"
########################################################
rpoplpush # Remove the last element of the list , Move it to a new list
127.0.0.1:6379> flushdb
OK
127.0.0.1:6379> RPUSH mylist "hello"
(integer) 1
127.0.0.1:6379> RPUSH mylist "hello1"
(integer) 2
127.0.0.1:6379> RPUSH mylist "hello2"
(integer) 3
127.0.0.1:6379> RPOPLPUSH mylist myotherlist
"hello2"
127.0.0.1:6379> LRANGE mylist 0 -1 # Look at the original list
1) "hello"
2) "hello1"
127.0.0.1:6379> LRANGE myotherlist 0 -1 # Look at the target list , Values do exist
1) "hello2"
########################################################
LSET Replaces the value of the specified subscript in the list with another value , update operation
127.0.0.1:6379> flushdb
OK
127.0.0.1:6379> EXISTS list # First determine whether the list exists
(integer) 0
127.0.0.1:6379> LSET list 0 item # If there is no list to update, an error will be reported
(error) ERR no such key
127.0.0.1:6379> LPUSH list value1
(integer) 1
127.0.0.1:6379> LRANGE list 0 0
1) "value1"
127.0.0.1:6379> LSET list 0 item # If there is , Update the value of the current subscript
OK
127.0.0.1:6379> LRANGE list 0 0
1) "item"
127.0.0.1:6379> LSET list 1 other # If it doesn't exist , May be an error
(error) ERR index out of range
########################################################
LINSERT Put a specific value Insert before or after an element !
127.0.0.1:6379> flushdb
OK
127.0.0.1:6379> LPUSH mylist "hello"
(integer) 1
127.0.0.1:6379> LPUSH mylist "world"
(integer) 2
127.0.0.1:6379> LINSERT mylist before world "other"
(integer) 3
127.0.0.1:6379> LRANGE mylist 0 -1
1) "other"
2) "world"
3) "hello"
127.0.0.1:6379> LINSERT mylist after world "new"
(integer) 4
127.0.0.1:6379> LRANGE mylist 0 -1
1) "other"
2) "world"
3) "new"
4) "hello"
Summary
- He's actually a linked list ,before Node after 、left、right You can insert values
- If key non-existent , Create a new list
- If key There is , The new content
- If you remove all the values , Empty list , It also means that there is no such thing as !
- Insert or change values on both sides , Highest efficiency ! The middle element , Relatively speaking, the efficiency will be a little lower
Message queuing ! Message queue (Lpush Rpop) Left and right exit - queue Stack (Lpush Lpop) Left and left out
边栏推荐
猜你喜欢
![[Part 14] source code analysis and application details of completionservice class [key]](/img/41/9f5383d6eafb32723e29c15da3a1af.jpg)
[Part 14] source code analysis and application details of completionservice class [key]

Goto statement of go language

解决 img 5px 间距的问题
![[advanced C language] integer storage in memory](/img/a5/6c7df3b8f427fe724922a6b853516f.png)
[advanced C language] integer storage in memory

LeetCode-76-最小覆盖子串

LabVIEW控制Arduino实现红外测距(进阶篇—6)

Which Bluetooth headset is better within 500? Inventory of gifts for girls' Day

Tensorflow 2. X Getting Started tutorial

LeetCode-43-字符串相乘

js对返回的数据的各种数据类型进行非空判断。
随机推荐
Codeworks round 739 (Div. 3) problem solving Report
LeetCode-322-零钱兑换
The official announced the launch of Alibaba's 2023 global school recruitment: Technical Posts account for more than 60%
Network security Kali penetration learning introduction to web penetration using MSF penetration to attack win7 host and execute commands remotely
Leetcode 797. All possible paths
作为一名 ABAP 资深顾问,下一步可以选择哪一门 SAP 技术作为主攻方向?
2021-09-11 训练场补题
go语言的goto语句
Serval and Rooted Tree(CF1153D)-DP
Goland中在文件模板中为go文件添加个人声明
JS performs non empty judgment on various data types of the returned data.
Codeforces Round #740 Div. 2 解题报告
Stream Chinese sorting
解决 img 5px 间距的问题
My collection of scientific research websites
LabVIEW控制Arduino实现红外测距(进阶篇—6)
Regular check matches positive integer or decimal limit between [0-100] and [0-1000]
一个Golang的私有库设置问题
一步步把 SAP UI5 应用部署到 SAP BTP Kyma 运行环境中去
How to Load Data from CSV (Data Preparation Part)