Skip to main content
Use MEMORY USAGE to estimate how many bytes a key and its value occupy in memory. The figure covers the stored data along with its internal overhead, so it is larger than the raw size of the value and is meant for comparing keys rather than for exact accounting. For aggregate types such as hashes, lists, sets, sorted sets, and streams the value is sampled instead of fully traversed: SAMPLES sets how many nested elements are inspected, and the value is clamped to the range this deployment supports, so it tunes the estimate rather than forcing an exact traversal. A missing key returns null. It is the usual way to find out which keys are responsible for memory growth before deciding what to trim or restructure.

Syntax

Arguments

Important points

  • The result is an estimate in bytes and can change as the internal representation changes.
  • A missing key returns null. The sampling count is clamped to the deployment’s supported range.

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.
This command is not supported yet in @upstash/redis.
This command is not supported yet in upstash_redis.