Redis 过期策略与源码分析
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                Redis 过期策略与源码分析
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.                        
                                在 Redis 中我們可以給一些元素設(shè)置過期時間,那當它過期之后 Redis 是如何處理這些過期鍵呢?
過期鍵執(zhí)行流程
Redis 之所以能知道那些鍵值過期,是因為在 Redis 中維護了一個字典,存儲了所有設(shè)置了過期時間的鍵值,我們稱之為過期字典。
過期鍵判斷流程如下圖所示:
過期鍵源碼分析
過期鍵存儲在 redisDb 結(jié)構(gòu)中,源代碼在 src/server.h 文件中:
/* Redis database representation. There are multiple databases identified* by integers from 0 (the default database) up to the max configured* database. The database number is the 'id' field in the structure. */ typedef struct redisDb {dict *dict; /* 數(shù)據(jù)庫鍵空間,存放著所有的鍵值對 */dict *expires; /* 鍵的過期時間 */dict *blocking_keys; /* Keys with clients waiting for data (BLPOP)*/dict *ready_keys; /* Blocked keys that received a PUSH */dict *watched_keys; /* WATCHED keys for MULTI/EXEC CAS */ 創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的Redis 过期策略与源码分析的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 第 6-2 课:SpringMVC 核心
- 下一篇: Redis 消息队列的三种方案(List
