Redis 更新(set) key值过期时间被重置


Redis 更新(set) key值过期时间被重置的问题:

问题描述:

当你在redis中插入一个key值,并且设置了对应过期时间.,当过期时间还没到的时候重新更新 key 值会导致过期时间被刷新。

针对这个问题 redis 的官方文档是这么解释的:

The timeout will only be cleared by commands that delete or overwrite the contents of the key, including DEL, SET, GETSET and all the *STORE commands. This means that all the operations that conceptually alter the value stored at the key without replacing it with a new one will leave the timeout untouched. For instance, incrementing the value of a key with INCR, pushing a new value into a list with LPUSH, or altering the field value of a hash with HSET are all operations that will leave the timeout untouched.

大致意思:

如果用DEL, SET, GETSET会将key对应存储的值替换成新的,命令也会清除掉超时时间;如果 list 结构中添加一个数据或者改变hset数据的一个字段是不会清除超时时间的;如果想要通过set去覆盖值那就必须重新设置expire。

相关阅读 >>

为什么Redis是单线程、及高并发快原因详解

Redis如何实现扩容

聊聊Redis中的哨兵模式

Redis除了做缓存还能做什么

Redis集群怎么同步

介绍Redis性能监控

Redis有序集合的相关命令有哪些

Redis info命令介绍

Redis主要消耗什么资源

Redis实现限速器的几种方式

更多相关阅读请进入《Redis》频道 >>


数据库系统概念 第6版
书籍

数据库系统概念 第6版

机械工业出版社

本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...