redis 删除超时key
来源:互联网 发布:cv配音软件下载 编辑:程序博客网 时间:2024/05/17 05:59
该功能主要通过expireIfNeeded 这个函数来实现的,redis对于需要设置超时的key,放到了单独的一个hash中,所以只要检测这个超时hash就可以了。
//检查是否超时,超时了那么就删除int expireIfNeeded(redisDb *db, robj *key) { time_t when = getExpire(db,key); //该key没有设置超时 if (when < 0) return 0; /* No expire for this key */ //正在载入 /* Don't expire anything while loading. It will be done later. */ if (server.loading) return 0; //如果是slave, 它不需要直接进行删除的,它的删除有master来控制的,但是它需要调用者一个返回直:是不是超时. /* If we are running in the context of a slave, return ASAP: * the slave key expiration is controlled by the master that will * send us synthesized DEL operations for expired keys. * * Still we try to return the right information to the caller, * that is, 0 if we think the key should be still valid, 1 if * we think the key is expired at this time. */ if (server.masterhost != NULL) { return time(NULL) > when; } //存在但未超时 /* Return when this key has not expired */ if (time(NULL) <= when) return 0; //删除并通知文件和slave /* Delete the key */ server.stat_expiredkeys++; propagateExpire(db,key); return dbDelete(db,key);}
对不同的情况,做不同的处理,我们再来看看propageteExpire函数
void propagateExpire(redisDb *db, robj *key) { robj *argv[2]; argv[0] = createStringObject("DEL",3); argv[1] = key; incrRefCount(key); //只有在appendonly开启的时候,才进行操作 if (server.appendonly) feedAppendOnlyFile(server.delCommand,db->id,argv,2); if (listLength(server.slaves)) replicationFeedSlaves(server.slaves,db->id,argv,2); decrRefCount(argv[0]); decrRefCount(argv[1]);}
如果开启了appendonly,那么从append文件中进行删除。
如果存在slaves,那么从slave中进行删除
- redis 删除超时key
- Redis批量删除Key
- 批量删除 redis key
- redis批量删除key
- redis 批量删除key
- redis批量删除key
- redis 批量删除key
- 删除redis所有KEY
- redis批量删除key
- redis批量删除key
- Redis批量删除key
- Redis批量删除key
- Redis批量删除key
- Redis批量删除key
- redis 模糊删除key
- redis批量删除Key
- redis 删除所有key
- redis 批量删除key
- 练手的项目
- 哈佛公开课《Positive Psychology 1504》学习笔记 -- Beliefs
- 永中Office 2012 个人版发布!For Linux 小测试体验
- HTTP 格式
- Java数据结构课程设计 学生成绩管理
- redis 删除超时key
- 10g ASM下加控制文件 .
- zoj 3587 Marlon's String
- 如何使用spring的autowire为servlet注入bean
- 通过函数名调用函数
- 驱动注册的probe函数
- 南京大学计算机研究生复试面试题
- UML 简介
- 如何使用 MySQL Administrator 管理/备份/还原 My SQL 数据库