当前位置:网站首页>Redis-列表
Redis-列表
2022-07-06 01:29:00 【冰点契约丶】
Redis列表(List)
介绍
- 单键多值
- Redis 列表是简单的字符串列表,按照插入顺序排序。你可以添加一个元素到列表的头部(左边)或者尾部(右边)
- 它的底层实际是个双向链表,对两端的操作性能很高,通过索引下标的操作中间的节点性能会较差
常用命令
从左边插入一个或多个值
lpush <key> <value1> <value2> ...
从右边插入一个或多个值
rpush <key> <value1> <value2> ...
从左边弹出一个值(值会被删除)
lpop <key>
从右边弹出一个值(值会被删除)
rpop <key>
从列表key1右边弹出一个值插入到key2左边
rpoplpush <key1> <key2>
根据索引批量获取元素(-1代表最后一个元素)
lrange <key> <start> <stop>
根据索引获取单个元素(从左到右)
lindex <key> <index>
获取列表长度
llen <key>
在value之前插入元素target
linsert <key> before <value> <target>
从左边删除n个值为value的元素
lrem <key> <n> <value>
将列表中索引为index的值替换为value
lset <key> <index> <value>
列表的底层数据结构
- List的数据结构为快速链表quickList
- 首先在列表元素较少的情况下会使用一块连续的内存存储,这个结构是ziplist,也即是压缩列表(类似于顺序表),它将所有的元素紧挨着一起存储,分配的是一块连续的内存,当数据量比较多的时候才会改成quicklist,因为普通的链表需要的附加指针空间太大,会比较浪费空间。比如这个列表里存的只是int类型的数据,结构上还需要两个额外的指针prev和next
- Redis将链表和ziplist结合起来组成了quicklist,也就是将多个ziplist使用双向指针串起来使用。这样既满足了快速的插入删除性能,又不会出现太大的空间冗余
边栏推荐
- Vulhub vulnerability recurrence 74_ Wordpress
- 【详细】快速实现对象映射的几种方式
- 【全网最全】 |MySQL EXPLAIN 完全解读
- Code review concerns
- Basic operations of databases and tables ----- primary key constraints
- DOM introduction
- 2022 Guangxi Autonomous Region secondary vocational group "Cyberspace Security" competition and its analysis (super detailed)
- How to get the PHP version- How to get the PHP Version?
- Nmap: network detection tool and security / port scanner
- Huawei Hrbrid interface and VLAN division based on IP
猜你喜欢
Test de vulnérabilité de téléchargement de fichiers basé sur dvwa
Basic operations of databases and tables ----- primary key constraints
How to see the K-line chart of gold price trend?
ThreeDPoseTracker项目解析
MySQL learning notes 2
Basic operations of databases and tables ----- unique constraints
电气数据|IEEE118(含风能太阳能)
3D vision - 4 Getting started with gesture recognition - using mediapipe includes single frame and real time video
Hcip---ipv6 experiment
servlet(1)
随机推荐
晶振是如何起振的?
Huawei Hrbrid interface and VLAN division based on IP
Huawei converged VLAN principle and configuration
VMware Tools安装报错:无法自动安装VSock驱动程序
电气数据|IEEE118(含风能太阳能)
NLP第四范式:Prompt概述【Pre-train,Prompt(提示),Predict】【刘鹏飞】
Format code_ What does formatting code mean
Idea sets the default line break for global newly created files
How does the crystal oscillator vibrate?
SSH login is stuck and disconnected
SPIR-V初窺
Tcpdump: monitor network traffic
yii中console方法调用,yii console定时任务
【Flask】官方教程(Tutorial)-part1:项目布局、应用程序设置、定义和访问数据库
SPIR-V初窥
leetcode刷题_平方数之和
VMware Tools installation error: unable to automatically install vsock driver
Netease smart enterprises enter the market against the trend, and there is a new possibility for game industrialization
Superfluid_ HQ hacked analysis
[solved] how to generate a beautiful static document description page