Skip to main content
Use DBSIZE to get the number of keys stored in the database. The count covers keys of every type, and keys whose expiration has passed but that have not been removed yet may still be included, so treat the number as an accurate but momentary figure rather than an exact one. It is the quick way to see how a keyspace is growing, and unlike KEYS it does not build a list of key names to do so.

Syntax

Arguments

This command takes no arguments.

Important points

  • This operation can inspect a large part of the database. Prefer cursor-based scans where possible and avoid unbounded use on hot paths.

Response

The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.
Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.

Examples

TCP examples use the TLS REDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.

Related topics

DBSIZEOverview