Redis set值時過期時間重置問題

 

開發的過程中遇到了一個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。

-- 待測:1、使用setrange是否會重置過期時間   2、set值後重置的過期時間ttl時-1,還是大於0

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章