Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Redis · Command

PERSIST

Removes the existing expiration from a key, making it persistent. Returns 1 when a timeout was removed, otherwise 0.

Since
Redis Open Source 2.2.0

How it works

PERSIST removes the expiration associated with a key. The key remains present and becomes persistent; the command reports whether an expiration was actually removed.

Syntax

PERSIST key

Parameters

NameTypeDescription
keykeyThe name of the key.

Returns

Integer reply: 1 if the timeout has been removed; 0 if the key does not exist or does not have an associated timeout.

Key points

  • PERSIST removes the current expiration and makes the key persistent.
  • Once its timeout is removed, the key will not expire because it has no associated timeout.
  • A return value of 1 confirms that PERSIST removed the timeout.
  • The command returns 0 when the named key is absent.
  • PERSIST completes in constant time.
  • Its required argument is the key name whose expiration should be removed.

Common mistakes

  • A return value of 0 does not distinguish between a missing key and an existing key without an expiration.

Example: Remove a key expiration

redis-cli SET session:123 "active"
redis-cli EXPIRE session:123 300
redis-cli PERSIST session:123
redis-cli TTL session:123

The final TTL is -1, showing that the key no longer has an expiration.

When to use it

Promote a cache entry to persistent

A cache entry must survive beyond its previously assigned TTL.

Keep selected application state

A session or configuration key should remain available indefinitely after a condition is met.

Cancel expiration

Application logic needs to cancel a scheduled key expiration.

Interview questions

QWhat does PERSIST do, and what does it return?

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.

QWhat are PERSIST's complexity and required argument?

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.

QDoes PERSIST delete or modify the key's value?

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.

  • EXPIRE
  • TTL

Source: PERSIST | Docs - Redis. Checked 2026-10-16.