Skip to main content

A simple command-line tool for analyzing memory usage across keys in a Redis database.

Project description

redis-sizer

A simple command-line tool for analyzing memory usage across keys in a Redis database.

Sample output

redis-sizer can help with the following problems:

  • Optimize caching strategy.
  • Gain insights into memory usage at different namespace levels.
  • Identify which parts of your application consume the most memory.

Installation

Install via pip:

pip install redis-sizer

Usage

Run redis-sizer by specifying the Redis host along with any desired options:

redis-sizer [OPTIONS] HOST

Options:

  • --port: Port number [default: 6379]
  • --db: DB number [default: 0]
  • --password: Password [default: None]
  • --socket-timeout: Socket timeout in seconds [default: 10]
  • --socket-connect-timeout: Socket connect timeout in seconds [default: 10]
  • --pattern: Pattern to filter keys [default: *]
  • --sample-size: Number of keys to sample [default: None]
  • --namespace-separator: Separator for key namespaces [default: :]
  • --namespace-level: Maximum number of namespace levels to aggregate keys by. 0 means no aggregation. [default: 0]
  • --memory-unit: Memory unit for display in result table [default: B]
  • --top: Maximum number of rows to display in result table [default: 10]
  • --scan-count: COUNT option for scanning keys [default: 1000]
  • --batch-size: Batch size for calculating memory usage [default: 1000]

Aggregating Memory Usage by Key Groups

Many applications using Redis adopt hierarchical key naming conventions. redis-sizer leverages this structure to aggregate and analyze memory usage, helping you quickly identify which key groups consume the most memory.

For example, if your keys follow a colon-delimited format (e.g., users:profiles:..., users:logs:..., sessions:active:...), the hierarchy can be visualized like a tree structure:

DB
├── users:
│   ├── profiles:
│   │   ├── ...
│   └── logs:
│       ├── ...
├── sessions:
│   └── active:
...

Using --namespace-level 2 prints out memory usage tabels up to the second-level namespace:

Example output

Considerations

  • Since data can change during analysis, the final result may not accurately reflect the database’s state at the beginning of the process.
  • For databases with large collections of keys, consider using the --sample-size option to balance processing time with accuracy. If --sample-size is not specified, redis-sizer will perform perform a full iteration.
  • Increasing --scan-count or --batch-size can reduce network overhead. However, this can increase the load on the Redis server without providing meaningful performance improvements and, in some cases, may even lead to server blocking. Adjust these values carefully based on your server’s capacity.

Redis Version Compatibility

  • This tool relies on the Redis MEMORY USAGE command, which has been available since version 4.0.0.
  • It has been tested and verified to work with Redis versions 4, 5, 6, and 7.

Dependencies

redis-sizer depends on:

  • redis-py: to communicate with the Redis database.
  • typer: to build CLI application, with output formatting supported by rich

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

redis_sizer-0.3.0.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

redis_sizer-0.3.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file redis_sizer-0.3.0.tar.gz.

File metadata

  • Download URL: redis_sizer-0.3.0.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.23.0 CPython/3.11.4 Darwin/24.3.0

File hashes

Hashes for redis_sizer-0.3.0.tar.gz
Algorithm Hash digest
SHA256 8ba576c8076c5b9b5e87a48247417a5f4a6bd587ab3161806349b9b984805265
MD5 c38a00f0bc3ba2d09b393db32c71ffa2
BLAKE2b-256 e3d76dd0f59310da6ec71bbb7ea7c2eb457daf27072f394ec0afce2647fbea15

See more details on using hashes here.

File details

Details for the file redis_sizer-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: redis_sizer-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.23.0 CPython/3.11.4 Darwin/24.3.0

File hashes

Hashes for redis_sizer-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3bb6a44cb6c71319f1d719c454ec91ecf6c967758df916c5e93d2575fc362909
MD5 6b1f6e2cbe0181a7d1c93f4966cc949a
BLAKE2b-256 53cc94949cae24126b304af5de9ba0e14e765b15b1d2045d785d56d176d30b73

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page