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.
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: 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:COUNToption 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:001, users:logs:login:002), the hierarchy can be visualized like a tree structure:
DB
├── users:
│ ├── profiles:
│ │ ├── 001
│ │ └── 002
│ └── logs:
│ ├── 001
│ └── 002
├── sessions:
│ └── active:
...
Use --namespace-level 1 to aggregate memory usage at the top-level namespace:
Key │ Count │ Size (MB) │ ... │ Memory Usage (%)
╶────────────────────┼─────────┼───────────┼─────┼──────────────────╴
users │ 350000 │ 2460.86 │ ... │ 93.82
sessions │ 60000 │ 140.23 │ ... │ 5.35
cache │ 10000 │ 20.07 │ ... │ 0.77
tokens │ 700 │ 1.75 │ ... │ 0.07
╶────────────────────┼─────────┼───────────┼─────┼──────────────────╴
Total Keys Scanned │ 420700 │ 2622.90 │ ... │ 100.00
Use --namespace-level 2 to aggregate memory usage at the second-level namespace:
Key │ Count │ Size (MB) │ ... │ Memory Usage (%)
╶────────────────────┼─────────┼───────────┼─────┼──────────────────╴
users:profiles │ 100000 │ 1177.22 │ ... │ 44.88
users:logs │ 200000 │ 988.01 │ ... │ 37.67
sessions:active │ 50000 │ 295.64 │ ... │ 11.27
cache:images │ 40000 │ 100.02 │ ... │ 3.81
cache:queries │ 20000 │ 40.21 │ ... │ 1.53
tokens:auth │ 700 │ 1.75 │ ... │ 0.07
╶────────────────────┼─────────┼───────────┼─────┼──────────────────╴
Total Keys Scanned │ 420700 │ 2622.90 │ ... | 100.00
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-sizeoption to balance processing time with accuracy. If--sample-sizeis not specified, redis-sizer will perform perform a full iteration. - Increasing
--scan-countor--batch-sizecan 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 USAGEcommand, 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:
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file redis_sizer-0.1.0.tar.gz.
File metadata
- Download URL: redis_sizer-0.1.0.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.23.0 CPython/3.11.4 Darwin/24.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba733c83d6b55aa82db2f42474bb0cab2ca51c7c50c6943512d8c7f0c1d5dc8b
|
|
| MD5 |
ba8e2939861dabba66fbe3447c0f42e3
|
|
| BLAKE2b-256 |
e2b75d9b992a7132caab7761b5dc2e01f9c5d1fb0c5bb5626a580bb0500375a2
|
File details
Details for the file redis_sizer-0.1.0-py3-none-any.whl.
File metadata
- Download URL: redis_sizer-0.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
548428dfdc5afcf865b1a51a9b2a1c0ea9606f52557f597decbfa832dcbd1e37
|
|
| MD5 |
51ea44623b4003e310d6954f5a5a0447
|
|
| BLAKE2b-256 |
2260e455e65c942c7a166b7bee00d02a2a3ed0bda145d80e4bedca6bebfefa6b
|