When python sets the expiration time of a key in redis to-1, why is this key destroyed directly?

key_name = "test_h"
redis.expire(key_name, -1)
redis.execute()

This key is destroyed directly in

redis. Why?

Jan.18,2022

The

python function is a wrapper for commands. Look directly at the document examples

redis> SET mykey "Hello"
OK
redis> EXPIRE mykey 10
(integer) 1
redis> TTL mykey
(integer) 10
redis> SET mykey "Hello World"
OK
redis> TTL mykey
(integer) -1
redis> 

you can see that the expiration time when deleting key is-1

look at Normally Redis keys are created without an associated time to live. again The key will simply live forever, unless it is removed by the user in an explicit way
means that if the expiration time is not set, it will never expire


has expired. If it expires, it will be destroyed


if you want it to never expire, use redis.persist (key)

Menu