Skip to content


Posted on:September 25, 2021 at 11:34 PM

1 类型 string
list set zset hash

2 对应的命令

set 命令 edis/src/t_string.c
string 的过期不是实时的

list lpush lpop / 有ziplist 和双向链表组成

hash 有两个hashtable , 一个是内容一个谁拿来扩容

set 谁由intset 和 hashtable组成

zset ziplist+ skiplist

3 aof/rdb

aof 谁append only file 都是可读的文本 rdb谁整个盘快照

4 redis 淘汰

allkeys-lru: 对所有的键都采取LRU淘汰
volatile-lru: 仅对设置了过期时间的键采取LRU淘汰
allkeys-random: 随机回收所有的键
volatile-random: 随机回收设置过期时间的键
volatile-ttl: 仅淘汰设置了过期时间的键---淘汰生存时间TTL(Time To Live)更小的键

5 HA

Redis Cluster master-replica model

In order to remain available when a subset of master nodes are failing or are not able to communicate with the majority of nodes, Redis Cluster uses a master-replica model where every hash slot has from 1 (the master itself) to N replicas (N-1 additional replica nodes).

In our example cluster with nodes A, B, C, if node B fails the cluster is not able to continue, since we no longer have a way to serve hash slots in the range 5501-11000.

However when the cluster is created (or at a later time) we add a replica node to every master, so that the final cluster is composed of A, B, C that are master nodes, and A1, B1, C1 that are replica nodes. This way, the system is able to continue if node B fails.

Node B1 replicates B, and B fails, the cluster will promote node B1 as the new master and will continue to operate correctly.

However, note that if nodes B and B1 fail at the same time, Redis Cluster is not able to continue to operate.

failover 错误转移

当master 失去连接后,slave会向master 发起一个paxos 选票


分片会路由到不同胡slot,运算方式要crc16(key)% 16384




Redis Cluster is not able to guarantee strong consistency. In practical terms this means that under certain conditions it is possible that Redis Cluster will lose writes that were acknowledged by the system to the client.

The first reason why Redis Cluster can lose writes is because it uses asynchronous replication. This means that during writes the following happens:

Your client writes to the master B.
The master B replies OK to your client.
The master B propagates the write to its replicas B1, B2 and B3.


缓存穿透 雪崩

穿透是指通过redis 雪崩就是指同时失效