Promote a cache entry to persistent
A cache entry must survive beyond its previously assigned TTL.
Redis · Command
Removes the existing expiration from a key, making it persistent. Returns 1 when a timeout was removed, otherwise 0.
PERSIST removes the expiration associated with a key. The key remains present and becomes persistent; the command reports whether an expiration was actually removed.
PERSIST key| Name | Type | Description |
|---|---|---|
key | key | The name of the key. |
Integer reply: 1 if the timeout has been removed; 0 if the key does not exist or does not have an associated timeout.
redis-cli SET session:123 "active"
redis-cli EXPIRE session:123 300
redis-cli PERSIST session:123
redis-cli TTL session:123The final TTL is -1, showing that the key no longer has an expiration.
A cache entry must survive beyond its previously assigned TTL.
A session or configuration key should remain available indefinitely after a condition is met.
Application logic needs to cancel a scheduled key expiration.
PERSIST key removes the key's existing timeout, changing it from volatile to persistent. It returns 1 when a timeout was removed and 0 when the key is missing or has no timeout.
Follow-up: How can you verify the result? Use TTL: it returns -1 for an existing key with no associated timeout.
The command has O(1) time complexity. It takes one required argument, key, which identifies the key whose expiration should be removed.
Follow-up: What is the command syntax? PERSIST key.
PERSIST changes expiration metadata; it does not delete the key or alter its value. After successful removal, the key remains available without an associated timeout.
Follow-up: What happens if the key already has no timeout? The command returns 0 and leaves that state unchanged.
EXPIRETTL