Skip to main content

Redis Key Analyzer is a CLI tool for scanning and analyzing Redis database keys, providing insights into their distribution, type, memory usage, and TTL.

Project description

redis-key-analyzer

Overview

redis-key-analyzer is a tool designed to analyze Redis keys, providing detailed statistics on key patterns, memory usage, TTL (Time to Live), and more. This tool is useful for understanding the distribution and characteristics of keys in a Redis database, which can help in optimizing and managing Redis instances.

Features

  • Analyze Redis keys based on patterns, prefixes, and separators.
  • Collect statistics on key types, memory usage, and TTL.
  • Support for read-only Redis clusters.
  • Configurable batch size and sleep intervals for large datasets.

Installation

To install redis-key-analyzer, use pip:

pip install redis-key-analyzer

Usage

You can use the redis-key-analyzer via the command line interface (CLI). Below are the available options:

Usage: redis-key-analyzer [OPTIONS]

Options:
  --host TEXT          Redis host. Default is 'localhost'.
  --port INTEGER       Redis port. Default is 6379.
  --db INTEGER         Redis database. Default is 0.
  --read-only, -ro     Check read-only cluster.
  --match, -m TEXT     Redis key pattern. Default is '*'.
  --batch-size INTEGER Batch size. Default is 1000.
  --prefix TEXT        Prefixes for key pattern. Example: --prefix 'prefix1 prefix2'.
  --separator TEXT     Separators for key pattern. Default is ':'.
  --separator-max-depth INTEGER Max depth for separator. Default is 1.
  --limit INTEGER      Limit total keys. -1 for no limit. Default is -1.
  --sleep INTEGER      Sleep seconds between batches. -1 for no sleep. Default is -1.
  --help               Show this message and exit.

Search

rka --host localhost [--port 6379] [--db 0] [-m '*']

+-------------+--------+-------+---------+---------+-------+--------------+-----------+------------+------------+----------+----------+--------------+
| pattern     | dtype  |  ttl  | avg_ttl | max_ttl | count | total_memory | memory_hu | memory_avg | memory_max | size_avg | size_max | key(max_ttl) |
+-------------+--------+-------+---------+---------+-------+--------------+-----------+------------+------------+----------+----------+--------------+
| my-set      |  set   | NOTTL |    -1   |    -1   |   1   |          272 |  272.0  B |    272     |    272     |    3     |    3     | my-set       |
| my-list     |  list  | NOTTL |    -1   |    -1   |   1   |          223 |  223.0  B |    223     |    223     |    14    |    14    | my-list      |
| foos:<*>    | string |  TTL  |   524   |   984   |   3   |          183 |  183.0  B |     61     |     61     |    3     |    3     | foos:123     |
| my-hash     |  hash  | NOTTL |    -1   |    -1   |   1   |           87 |   87.0  B |     87     |     87     |    2     |    2     | my-hash      |
| my-zset     |  zset  | NOTTL |    -1   |    -1   |   1   |           83 |   83.0  B |     83     |     83     |    2     |    2     | my-zset      |
| user.sc:<*> |  hash  | NOTTL |    -1   |    -1   |   1   |           75 |   75.0  B |     75     |     75     |    1     |    1     | user.sc:123  |
| my-string   | string | NOTTL |    -1   |    -1   |   1   |           61 |   61.0  B |     61     |     61     |    3     |    3     | my-string    |
+-------------+--------+-------+---------+---------+-------+--------------+-----------+------------+------------+----------+----------+--------------+

CLI Usage Examples

1) Quick scan (defaults)

Scan localhost:6379, DB 0, all keys:

rka
# same as:
# rka --host localhost --port 6379 --db 0 --match '*'

2) Filter by pattern

Only analyze keys that match a specific glob pattern (e.g., sessions):

rka -m 'session:*'

3) Group by prefixes & separators

Tell the analyzer which prefixes matter, and how to split keys:

# Keys like "user:123", "user:profile:456", "order:789"
rka --prefix 'order:' --separator ':' --separator-max-depth 1
  • --separator ':': split keys on :

  • --separator-max-depth 1: group at most one level deep, e.g. user:<>, order:<>

  • --prefix 'user order': highlight these prefixes in grouping stats

3.1) --separator-max-depth examples:

Assume the following keys:

coupon:MKT-A:1001
coupon:MKT-A:1002
coupon:MKT-B:2001
coupon:MKT-B:2002

Depth = 1

Use only up to the first : as the grouping prefix.

rka --separator ':' --separator-max-depth 1

Aggregated pattern (example):

coupon:<*>

Depth = 2

Use up to the second : as the grouping prefix.

rka --separator ':' --separator-max-depth 2 -m 'coupon:*'

Aggregated patterns (example):

coupon:MKT-A:<*>
coupon:MKT-B:<*>

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-key-analyzer-0.1.6.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

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

redis_key_analyzer-0.1.6-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file redis-key-analyzer-0.1.6.tar.gz.

File metadata

  • Download URL: redis-key-analyzer-0.1.6.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for redis-key-analyzer-0.1.6.tar.gz
Algorithm Hash digest
SHA256 0303912f84a7af31e63164a9d4045761a035abea2e0f91c985a94af73e4b6ffc
MD5 98bf2d364a911a938d3718e8729b1964
BLAKE2b-256 0c54e26071aedad543d6cb7b9c230e556abb9d1eaca2a655908b2405e52beccb

See more details on using hashes here.

File details

Details for the file redis_key_analyzer-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for redis_key_analyzer-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 1457a7c04ef52a8b320d6b79c2d76fc65ceabac5086b8de8dd60c5a9f2421d7d
MD5 9eb14298cc665ce35fa789c2a607a3ed
BLAKE2b-256 7bffd5a618162cf1ffc4656041bc9036bb5a7e50409fd636559d88af36aa9d0d

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