Skip to main content
Return the total number of live keys in the database. This reads directly from the internal hash table counter.

Syntax

COUNT

Parameters

None.

Return value

Returns N, where N is the number of keys currently tracked by the hash table.

Examples

>>> SET a 1
OK
>>> SET b 2
OK
>>> COUNT
2

>>> DEL a
1
>>> COUNT
1
>>> BENCH 5
Inserted 5 entries in 0.00 seconds.
>>> COUNT
5

Notes

COUNT reflects ht->count, the internal key counter. This counter is decremented immediately on DEL and on passive expiry (when GET or TTL detects an expired key).
COUNT does not trigger an active expiry sweep. Keys that have passed their TTL but have not yet been accessed may still be included in the count. The reported value can be slightly higher than the number of keys that are actually retrievable.

Build docs developers (and LLMs) love