当前位置:网站首页>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线程也可以进行读写任务
边栏推荐
- 提升树莓派性能的方法
- SSRF漏洞file伪协议之[网鼎杯 2018]Fakebook1
- QQ medicine, Tencent ticket
- Sliding rail stepping motor commissioning (national ocean vehicle competition) (STM32 master control)
- Scripy tutorial classic practice [New Concept English]
- Show the mathematical formula in El table
- Introduction and basic use of stored procedures
- Ogre introduction
- . Net core about redis pipeline and transactions
- PHP中用下划线开头的变量含义
猜你喜欢

室内ROS机器人导航调试记录(膨胀半径的选取经验)

Getting started with MySQL

Use of polarscatter function in MATLAB
![Supply chain supply and demand estimation - [time series]](/img/2c/82d118cfbcef4498998298dd3844b1.png)
Supply chain supply and demand estimation - [time series]

Cinnamon taskbar speed

Storage principle inside mongodb

得物客服热线的演进之路

2022-7-7 Leetcode 34. Find the first and last positions of elements in a sorted array

. Net core about redis pipeline and transactions

Build a secure and trusted computing platform based on Kunpeng's native security
随机推荐
PHP - laravel cache
move base参数解析及经验总结
LED light of single chip microcomputer learning notes
Evolution of customer service hotline of dewu
Final review notes of single chip microcomputer principle
Ways to improve the performance of raspberry pie
AI人才培育新思路,这场直播有你关心的
作战图鉴:12大场景详述容器安全建设要求
Deep understanding of array related problems in C language
为租客提供帮助
THINKPHP框架的优秀开源系统推荐
Signal strength (RSSI) knowledge sorting
The delivery efficiency is increased by 52 times, and the operation efficiency is increased by 10 times. See the compilation of practical cases of financial cloud native technology (with download)
Centso7 OpenSSL error Verify return code: 20 (unable to get local issuer certificate)
Realize the IP address home display function and number home query
Cmake learning and use notes (1)
Getting started with MySQL
2022-7-7 Leetcode 34.在排序数组中查找元素的第一个和最后一个位置
Excerpt from "misogyny: female disgust in Japan"
C语言数组相关问题深度理解