Upstash Documentation

DBSIZE

Get number of keys in database.
2 min read

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.

ProtocolReply
RESP2Integer
RESP3Integer
Note

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.

Redis CLI
@upstash/redis
upstash_redis
ioredis
node-redis
redis-py
go-redis
jedis
redis-rs