Redis 更新(set) key值 會重置過期時間問題


摘自:https://blog.csdn.net/weixin_38399962/article/details/82697498

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

 

所以: 重新set , getset 會重置過期時間, 希望各位遇到這類問題,做好准備.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM