本文内容为 http://www.redis.io/commands/persist 的翻译、注解、例子扩充及其它修改。感谢 Redis 作者 Antirez 为开源社区作出的贡献,本文保证最新、最准、最全以表示对其的敬意。欢迎留言纠错、提示更新或支持。
PERSIST key

删除键 key 上的过期属性。将该键从不稳定的(Volatile)转变成持久的(Persistent)

Remove the existing timeout on key, turning the key from volatile (a key with an expire set) to persistent (a key that will never expire as no timeout is associated).
  • 如果超时属性被移除,则返回 1

    如果键不存在,或没有关联的超时属性,则返回 0

    1 if the timeout was removed.

    0 if key does not exist or does not have an associated timeout.

  • redis> SET mykey "Hello"
    OK
    redis> EXPIRE mykey 10
    (integer) 1
    redis> TTL mykey
    (integer) 10
    redis> PERSIST mykey
    (integer) 1
    redis> TTL mykey
    (integer) -1
  • 版本支持

    2.2.0+

    时间复杂度(Time complexity)

    O(1)