Skip to main content
These commands operate on keys regardless of their type. You use them to delete keys, manage expiry, iterate the keyspace, inspect a key’s type, rename keys, and measure memory consumption. Because they work across all data types, they’re the building blocks for housekeeping routines, cache eviction policies, and operational dashboards.

DEL

Deletes one or more keys. Keys that do not exist are silently ignored. Syntax: DEL key [key ...]
Returns: Integer — the number of keys that were actually deleted.

EXISTS

Returns how many of the specified keys currently exist. You can name the same key multiple times and it will be counted once per occurrence. Syntax: EXISTS key [key ...]
Returns: Integer — count of the keys that exist.

EXPIRE

Sets a time-to-live on key in seconds. After the timeout elapses, the key is automatically deleted. Any existing TTL is replaced. Syntax: EXPIRE key seconds
Returns: 1 if the timeout was set, 0 if the key does not exist.

PEXPIRE

Sets a time-to-live on key in milliseconds. Syntax: PEXPIRE key milliseconds
Returns: 1 if the timeout was set, 0 if the key does not exist.

EXPIREAT

Sets the expiry of key to an absolute Unix timestamp in seconds. Syntax: EXPIREAT key unix-seconds
Returns: 1 if the timeout was set, 0 if the key does not exist.

PEXPIREAT

Sets the expiry of key to an absolute Unix timestamp in milliseconds. Syntax: PEXPIREAT key unix-milliseconds
Returns: 1 if the timeout was set, 0 if the key does not exist.

TTL

Returns the remaining time-to-live of key in seconds. Syntax: TTL key
Returns: Seconds remaining as an integer. Returns -1 if the key exists but has no TTL. Returns -2 if the key does not exist.

PTTL

Returns the remaining time-to-live of key in milliseconds. Syntax: PTTL key
Returns: Milliseconds remaining. Returns -1 for no TTL; -2 if the key does not exist.

PERSIST

Removes the TTL from key, making it persistent. Has no effect on keys that have no TTL. Syntax: PERSIST key
Returns: 1 if the TTL was removed, 0 if the key does not exist or had no TTL.

KEYS

Returns all keys matching a glob pattern. Supported wildcards: * (any sequence), ? (any single character), [...] (character class). Syntax: KEYS pattern
Returns: Array of matching key names.
KEYS scans the entire keyspace and blocks the server while it runs. On large datasets this can cause significant latency spikes. Use SCAN in production instead.

SCAN

Incrementally iterates the keyspace without blocking the server. Start with cursor 0; repeat using the cursor returned in each response until the server returns cursor 0 again, signalling that a complete iteration has finished. Syntax: SCAN cursor [MATCH pattern] [COUNT n] [TYPE type]
integer
required
Start at 0 to begin a new scan. Use the cursor returned by the previous call to continue.
string
Filter keys by glob pattern (default *).
integer
Hint for how many keys to examine per call (default 10). This is an approximation — the actual number of keys returned may differ.
string
Filter by key type. Valid values: string, hash, list, set, zset, vector.
Returns: Two-element array: [next_cursor, [key, key, ...]]. When next_cursor is "0", the iteration is complete.

HSCAN / SSCAN / ZSCAN

Incrementally iterate the fields of a hash, the members of a set, or the members-and-scores of a sorted set, using the same cursor protocol as SCAN. Syntax:
  • HSCAN key cursor [MATCH pattern] [COUNT n]
  • SSCAN key cursor [MATCH pattern] [COUNT n]
  • ZSCAN key cursor [MATCH pattern] [COUNT n]
Returns: Two-element array [next_cursor, items]. HSCAN and ZSCAN return interleaved field/value or member/score pairs; SSCAN returns plain member strings.

TYPE

Returns the type of the value stored at key. Syntax: TYPE key
Returns: One of: string, hash, list, set, zset, vector, or none if the key does not exist.

RENAME

Renames key to newkey. If newkey already exists, it is overwritten. The TTL of the original key is preserved on the renamed key. Returns an error if key does not exist. Syntax: RENAME key newkey
Returns: OK on success, or an error if the source key does not exist.

RENAMENX

Renames key to newkey only if newkey does not already exist. This is the atomic, non-destructive variant of RENAME. Syntax: RENAMENX key newkey
Returns: 1 if the rename succeeded, 0 if newkey already exists. Returns an error if the source key does not exist.

MEMORY USAGE

Returns the approximate number of bytes that key and its value consume in memory. The SAMPLES option is accepted for compatibility with Redis tooling but is ignored — Cache-Pot always walks the full value. Syntax: MEMORY USAGE key [SAMPLES n]
Returns: Integer byte count, or nil if the key does not exist.
MEMORY USAGE reports a heuristic estimate, not an exact allocator measurement. Use it for relative comparisons and capacity planning rather than precise accounting.