当前位置:网站首页>Redis data type - list list
Redis data type - list list
2022-07-24 06:47:00 【Life goes on and battles go on】
list List( More than one value Value)
#=====================================
# lpush : Insert one or more values into the list header ( Left )
# rpush : Insert one or more values at the end of the list ( Right )
# lrange : Returns the elements in the specified interval in the list , The interval is offset by start and end Appoint
# among 0 Represents the first element of the category 1 Represents the second element of the list And so on
# You can also use negative subscripts With -1 Represents the last element of the list -2 Represents the penultimate element of a list And so on
#=====================================
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> lrange list 0 -1
1) "three"
2) "two"
3) "one"
127.0.0.1:6379> lrange list 0 1
1) "three"
2) "two"
127.0.0.1:6379>
#=====================================
# lpop : The command removes and returns the first element of the list . When category key When there is no return nil
# rpop: Remove the last element of the list , The return value is the removed element
#=====================================
127.0.0.1:6379> rpush list right
(integer) 3
127.0.0.1:6379> lpop list
"two"
127.0.0.1:6379> rpop list
"right"
127.0.0.1:6379> lrange list 0 -1
1) "one"
#=====================================
# lindex : Get elements according to index subscript (-1 On behalf of the last 0 On behalf of the first )
#=====================================
127.0.0.1:6379> lindex list 1
(nil)
127.0.0.1:6379> lindex list 0
"one"
127.0.0.1:6379> lindex list -1
"one"
#=====================================
# llen : Used to return the length of the list
#=====================================
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
#=====================================
# lrem key : According to the parameters count Value Remove the list and parameters value Equal elements
#=====================================
127.0.0.1:6379> lrem list 1 two
(integer) 1
127.0.0.1:6379> lrange list 0 -1
1) "three"
2) "one"
#=====================================
# ltrim key : Trim a list (trim) That is to say , Let the list keep only the elements in the specified range , Elements that are not in the specified range will be removed
#=====================================
127.0.0.1:6379> rpush mylist wyt
(integer) 1
127.0.0.1:6379> rpush mylist lmp
(integer) 2
127.0.0.1:6379> rpush mylist hyd
(integer) 3
127.0.0.1:6379> rpush mylist yjy
(integer) 4
127.0.0.1:6379> ltrim mylist 1 2
OK
127.0.0.1:6379> lrange mylist 0 -1
1) "lmp"
2) "hyd"
#=====================================
# rpoplpush : Remove the last element of the list , And add the element to another list and return
#=====================================
127.0.0.1:6379> rpush list hello
(integer) 1
127.0.0.1:6379> rpush list foo
(integer) 2
127.0.0.1:6379> rpush list bar
(integer) 3
127.0.0.1:6379> rpoplpush list myotherlist
"bar"
127.0.0.1:6379> lrange list 0 -1
1) "hello"
2) "foo"
127.0.0.1:6379> lrange myotherlist 0 -1
1) "bar"#=====================================
# lset key index value : Will list Sure Subscript to be index The value of the element of is set to value
#=====================================
127.0.0.1:6379> exists list # Empty list lset
(integer) 0
127.0.0.1:6379> lset list 0 item # Report errors
(error) ERR no such key
127.0.0.1:6379> lpush list one # For non empty lists lset
(integer) 1
127.0.0.1:6379> lrange list 0 -1
1) "one"
127.0.0.1:6379> lset list 0 new # Update value
OK
127.0.0.1:6379> lrange list 0 0
1) "new"
127.0.0.1:6379> lset list 1 new #index Out of range error
(error) ERR index out of range
# ===================================================# linsert key before/after pivot value Used to insert elements before or after elements in the list .# Will value value Insert into list key among , At value pivot Before or after .# ===================================================
Performance summary
- It's a list of strings ,left,right You can insert and add
- If the key doesn't exist , Create a new list
- If the key already exists , The new content
- If all values are removed , The corresponding bond disappears
- The operation of linked list is very efficient both in head and tail , But if it is to operate on the intermediate elements , The efficiency is very poor
边栏推荐
- 实验:LVM逻辑卷的建立、扩容、与删除
- kubernetes简介(kubernetes优点)
- 进程和计划任务管理
- Take you to understand the inventory deduction principle of MySQL database
- [jQuery自定义插件] 1 自定义缓存插件-jQueryCache
- ES10 subtotal flat and flatmap
- Why can't index be the key of V-for?
- 分组后返回每组中的最后一条记录 GROUP_CONCAT用法
- JSONObject按照key的A——Z顺序排序
- Identification of Chinese medicinal materials
猜你喜欢

mysql获取自增行标(区别mysql版本)

ESP32超详细学习记录:NTP同步时间

(静态,动态,文件)三个版本的通讯录

Special effects - when the mouse moves, stars appear to trail
![[lvgl] [stage summary 1]](/img/39/c6e96ae7971a2350769ef5b5950f8f.png)
[lvgl] [stage summary 1]

记录PHPSerializer工具类反序列化遇到的坑
![[lvgl (2)]](/img/f8/d04183cf74896295382765a9dfd88d.png)
[lvgl (2)]

Detailed explanation of class loader and parental delegation mechanism

Account and authority management

Sort by an attribute value of an object in the array
随机推荐
The character that appears the most times in the JS output string
类的加载器 和 双亲委派机制详解
这10种定时任务学会了,直接飘
Machine learning case: smoking in pregnant women and fetal health
[small object velocimeter] only principle, no code
oss授权单个bucket权限
It's not too much to fight a landlord in idea!
Why can't index be the key of V-for?
【波形/信号发生器】基于 STC1524K32S4 for C on Keil
带你深入了解MySQL数据库扣减库存原理
Jenkins CI CD
kubernetes简介(kubernetes优点)
Redis特殊数据类型-BitMap
[lvgl (5)] label usage
在IDEA里斗个地主不过分吧!
Take you to understand the inventory deduction principle of MySQL database
Sed command
object-oriented
【LVGL(2)】LVGL入门,在CodeBlock上进行模拟以及移植STM32
实验:LVM逻辑卷的建立、扩容、与删除