Redis-在使用save或者bgsave命令时redis会清除过期的key吗?

Redis-在使用save或者bgsave命令时redis会清除过期的key吗?

灵芸 发布于 2017-06-07 字数 195 浏览 1226 回复 2

redis的官方文档中说它的过期key不会立即删除,而是在访问那个key时或者不定期的随机删除。那我在调用save或者bgsave时redis会做删除过期key操作吗?如果不会的话那会不会把过期的key也保存到文件里了?

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜无邪 2017-09-23 2 楼

官方给的文档表明在调用save或者bgsave时redis会做删除过期key操作的,看官方给的解释吧:There is so a simple rule, write operations against volatile keys will destroy the key before to perform the operation. Why Redis uses this behavior? In order to retain an important property: a server that receives a given number of commands in the same sequence will end with the same dataset in memory. Without the delete-on-write semantic the state of the server depends on the time the commands were issued. This is not a desirable property in a distributed database that supports replication.不过不同的版本处理的策略可能不太一样,可以看一下redis 下key的过期时间详解 :expire
参考:
Expiring keys
redis 下key的过期时间详解 :expire

夜无邪 2017-07-28 1 楼

这个当然会被删除的,你可以看一下rdb.c源代码,里面有条语句就是用来过滤过期key的:

/* Save the expire time */
if (expiretime != -1) {
/* If this key is already expired skip it */
if (expiretime < now) continue;