What is the usage of the expire command in Redis?
In Redis, the expire command is used to set an expiration time for a key, causing it to automatically be deleted after a certain period of time. The usage of the expire command is as follows:
EXPIRE key seconds
In this case, the key is the key that needs an expiration time, and seconds represent the expiration time in seconds. For example, running the following command will set the expiration time for key1 to 60 seconds.
EXPIRE key1 60
After the expiration time is set, key1 will be automatically deleted after 60 seconds, and if you visit the key again, it will return nil. You can use the TTL command to check the remaining time for the key’s survival.