当前位置:网站首页>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线程也可以进行读写任务
边栏推荐
- Excerpt from "misogyny: female disgust in Japan"
- [QNX hypervisor 2.2 user manual]6.3.4 virtual register (guest_shm.h)
- What are the principles for distinguishing the security objectives and implementation methods that cloud computing security expansion requires to focus on?
- Leecode3. Longest substring without repeated characters
- Co create a collaborative ecosystem of software and hardware: the "Joint submission" of graphcore IPU and Baidu PaddlePaddle appeared in mlperf
- Esp32 construction engineering add components
- Realize the IP address home display function and number home query
- 一文读懂数仓中的pg_stat
- "Song of ice and fire" in the eleventh issue of "open source Roundtable" -- how to balance the natural contradiction between open source and security?
- 属性关键字Aliases,Calculated,Cardinality,ClientName
猜你喜欢

高等數學---第八章多元函數微分學1

2022-7-7 Leetcode 844. Compare strings with backspace

1. Deep copy 2. Call apply bind 3. For of in differences

How far can it go to adopt a cow by selling the concept to the market?

单片机学习笔记之点亮led 灯

flask session伪造之hctf admin

Ogre introduction

Co create a collaborative ecosystem of software and hardware: the "Joint submission" of graphcore IPU and Baidu PaddlePaddle appeared in mlperf

2022-7-6 Leetcode27. Remove the element - I haven't done the problem for a long time. It's such an embarrassing day for double pointers
![Supply chain supply and demand estimation - [time series]](/img/2c/82d118cfbcef4498998298dd3844b1.png)
Supply chain supply and demand estimation - [time series]
随机推荐
Social responsibility · value co creation, Zhongguancun network security and Information Industry Alliance dialogue, wechat entrepreneur Haitai Fangyuan, chairman Mr. Jiang Haizhou
2022-7-6 使用SIGURG来接受外带数据,不知道为什么打印不出来
社会责任·价值共创,中关村网络安全与信息化产业联盟对话网信企业家海泰方圆董事长姜海舟先生
Help tenants
Digital IC Design SPI
2022-7-7 Leetcode 34.在排序数组中查找元素的第一个和最后一个位置
Distributed transaction solution
高等數學---第八章多元函數微分學1
THINKPHP框架的优秀开源系统推荐
2022-7-6 sigurg is used to receive external data. I don't know why it can't be printed out
MySQL error 28 and solution
室内ROS机器人导航调试记录(膨胀半径的选取经验)
属性关键字Aliases,Calculated,Cardinality,ClientName
2022-7-6 Leetcode 977. Square of ordered array
cmake 学习使用笔记(一)
Esp32 series column
MySQL error 28 and solution
.net core 关于redis的pipeline以及事务
Data refresh of recyclerview
118. 杨辉三角