当前位置:网站首页>Redis 核心数据结构 & Redis 6 新特性详
Redis 核心数据结构 & Redis 6 新特性详
2022-07-07 11:49:00 【bingtanghulu_6】
目录
1.list
redis在redisDB中是一个k-V结构,存储在字典dict中,dict包含两个hashTable结构,以数组形式存在,其中list 是一个有序的数据结构,采用双端链表quicklist和ziplist作为底层实现。
[[email protected] ~]# cd /usr/local/redis-6.2.7
[[email protected] redis-6.2.7]# src/redis-server redis.conf
[[email protected] redis-6.2.7]# src/redis-cli
127.0.0.1:6379> lpush a-list a b c
(integer) 3
127.0.0.1:6379> rpush a-list e f g
(integer) 6
127.0.0.1:6379> rpush a-list e 1100 f g
(integer) 10
127.0.0.1:6379> type a-list
list
127.0.0.1:6379> object encoding a-list
"quicklist"
list的数据结构如下:
2.hash
hash在字段比较小时使用ziplist存储,比较大时采用hashtable存储,下图演示object encoding key编码由ziplist变化为hashtable的场景。
127.0.0.1:6379> hset a-hash name caiji age 35 f1 v1 f2 v2 f3 v3
(integer) 5
127.0.0.1:6379> hgetall a-hash
1) "name"
2) "caiji"
3) "age"
4) "35"
5) "f1"
6) "v1"
7) "f2"
8) "v2"
9) "f3"
10) "v3"
127.0.0.1:6379> type a-hash
hash
127.0.0.1:6379> object encoding a-hash
"ziplist"
127.0.0.1:6379> hset a-hash f4 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
(integer) 1
127.0.0.1:6379> hgetall a-hash
1) "f1"
2) "v1"
3) "name"
4) "caiji"
5) "f2"
6) "v2"
7) "age"
8) "35"
9) "f3"
10) "v3"
11) "f4"
12) "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
127.0.0.1:6379> type a-hash
hash
127.0.0.1:6379> object encoding a-hash
"hashtable"
hash的数据结构如下,可以通过设置redis.conf配置文件配置ziplist和hashtable的存储范围
面试题:string和hash选型和优缺点
3.Set
Set为无序的自动去重的数据类型,当都用整型存储时是有序的,底层使用intset数据结构,当用字符串存储时是无序的,使用hashtable存储。
127.0.0.1:6379> sadd a-set 1 2 3 5 10 9 4 4 4
(integer) 7
127.0.0.1:6379> smembers a-set
1) "1"
2) "2"
3) "3"
4) "4"
5) "5"
6) "9"
7) "10"
127.0.0.1:6379> type a-set
set
127.0.0.1:6379> object encoding a-set
"intset"
127.0.0.1:6379> sadd a-set a
(integer) 1
127.0.0.1:6379> smembers a-set
1) "a"
2) "3"
3) "10"
4) "9"
5) "4"
6) "2"
7) "5"
8) "1"
127.0.0.1:6379> type a-set
set
127.0.0.1:6379> object encoding a-set
"hashtable"
intset的数据结构如下,有三个元素。
4.Zset
skiplist原理,使用二半查找,索引方式形成索引树查找数据,第K层索引数=n/2^k。
127.0.0.1:6379> zadd a-zset 100 a 200 b 150 c
(integer) 3
127.0.0.1:6379> zrange a-zset 0 -1 withscores
1) "a"
2) "100"
3) "c"
4) "150"
5) "b"
6) "200"
127.0.0.1:6379> type a-zset
zset
127.0.0.1:6379> object encoding a-zset
"ziplist"
5.GeoHash
GeoHash是一个算法加上zset实现的
help @geo
geohash底层实现,经纬度编码规则如下。gethash只能发送模糊范围,不会发送具体经纬度,适用于精度不是那么高的场景
6.面试常见问题
1. redis的多线程模型,在redis.conf中搜索thread-I/O里面有详细注释
redis执行过程:read-解析resp协议-执行命令-写入
多线程默认是关闭的,可以设置redis.conf中io-thread参数,如下图
配置了io-threads-do-reads参数以后其他I/O线程也可以进行读写任务
边栏推荐
- Digital IC Design SPI
- Learning breakout 2 - about effective learning methods
- Read PG in data warehouse in one article_ stat
- 一文读懂数仓中的pg_stat
- Build a secure and trusted computing platform based on Kunpeng's native security
- Solve the cache breakdown problem
- Drawerlayout suppress sideslip display
- 2022-7-6 sigurg is used to receive external data. I don't know why it can't be printed out
- Milkdown control icon
- [dark horse morning post] Huawei refutes rumors about "military master" Chen Chunhua; Hengchi 5 has a pre-sale price of 179000 yuan; Jay Chou's new album MV has played more than 100 million in 3 hours
猜你喜欢
2022-7-7 Leetcode 844. Compare strings with backspace
作战图鉴:12大场景详述容器安全建设要求
[fortress machine] what is the difference between cloud fortress machine and ordinary fortress machine?
Thread pool reject policy best practices
Talk about pseudo sharing
AI人才培育新思路,这场直播有你关心的
Navicat运行sql文件导入数据不全或导入失败
118. Yanghui triangle
Xshell connection server changes key login to password login
Social responsibility · value co creation, Zhongguancun network security and Information Industry Alliance dialogue, wechat entrepreneur Haitai Fangyuan, chairman Mr. Jiang Haizhou
随机推荐
实现IP地址归属地显示功能、号码归属地查询
Getting started with cinnamon applet
Show the mathematical formula in El table
Realbasicvsr test pictures and videos
【日常训练--腾讯精选50】231. 2 的幂
Leetcode simple question sharing (20)
作战图鉴:12大场景详述容器安全建设要求
得物客服热线的演进之路
[fortress machine] what is the difference between cloud fortress machine and ordinary fortress machine?
Best practice | using Tencent cloud AI willingness to audit as the escort of telephone compliance
LIS longest ascending subsequence problem (dynamic programming, greed + dichotomy)
1. Deep copy 2. Call apply bind 3. For of in differences
Sliding rail stepping motor commissioning (national ocean vehicle competition) (STM32 master control)
参数关键字Final,Flags,Internal,映射关键字Internal
Detr introduction
Scripy tutorial classic practice [New Concept English]
Esp32 series column
ES日志报错赏析-Limit of total fields
Indoor ROS robot navigation commissioning record (experience in selecting expansion radius)
Mathématiques avancées - - chapitre 8 différenciation des fonctions multivariables 1