• Redis 更新(set) key值 会重置过期时间问题


    今天在开发的过程中遇到了一个Redis的问题: 当你在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。

  • 相关阅读:
    PythonStudy——os 操作系统 模块
    PythonStudy——sys:系统 模块
    PythonStudy——datatime 模块
    PythonStudy——calendar 模块
    PythonStudy——time 模块
    PythonStudy——shelve 模块
    PythonStudy——hashlib 模块
    PythonStudy——hmac 模块
    JDK的版本历史
    Zookeeper分布式协调服务
  • 原文地址:https://www.cnblogs.com/yumingzhao/p/10100559.html
Copyright © 2020-2023  润新知