Go to the official website and read the description of expire: It’s explained like this:
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.
If you use DEL, SET, GETSET, the value stored in the key will be replaced with a new one, and the command will also clear the timeout; if you add a piece of data to the list structure or change a field of the hset data, the timeout will not be cleared; If you want to overwrite the value through set, you must reset expire.
Go to the official website and read the description of expire:
It’s explained like this:
If you use DEL, SET, GETSET, the value stored in the key will be replaced with a new one, and the command will also clear the timeout; if you add a piece of data to the list structure or change a field of the hset data, the timeout will not be cleared; If you want to overwrite the value through set, you must reset expire.
Click the link
EXPIREAT and EXPIRE will reset the expiration time when updating value.
Get the expiration time of the key through ttl before set
After set, set the value of ttl to the expiration time
But there will be errors in this way. I don’t know if others have better methods.