redis-key-analyzer


Nameredis-key-analyzer JSON
Version 0.1.6 PyPI version JSON
download
home_pageNone
SummaryRedis Key Analyzer is a CLI tool for scanning and analyzing Redis database keys, providing insights into their distribution, type, memory usage, and TTL.
upload_time2025-09-06 09:19:34
maintainerNone
docs_urlNone
authorRyan Kang
requires_python>=3.9
licenseNone
keywords redis pypi redis keys analyzer
VCS
bugtrack_url
requirements click redis tqdm prettytable
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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:

```bash
pip install redis-key-analyzer
```

## Usage

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

```bash
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 

```bash
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:
```bash
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):

```bash
rka -m 'session:*'
```

### 3) Group by prefixes & separators

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

```bash
# 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:

```text
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.

```bash
rka --separator ':' --separator-max-depth 1
```
Aggregated pattern (example):
```bash
coupon:<*>
```

Depth = 2

Use up to the second : as the grouping prefix.

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

Aggregated patterns (example):
```bash
coupon:MKT-A:<*>
coupon:MKT-B:<*>
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "redis-key-analyzer",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "redis, pypi, redis keys analyzer",
    "author": "Ryan Kang",
    "author_email": "serious8builder@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/0c/54/e26071aedad543d6cb7b9c230e556abb9d1eaca2a655908b2405e52beccb/redis-key-analyzer-0.1.6.tar.gz",
    "platform": null,
    "description": "# redis-key-analyzer\n\n## Overview\n\n`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.\n\n## Features\n\n- Analyze Redis keys based on patterns, prefixes, and separators.\n- Collect statistics on key types, memory usage, and TTL.\n- Support for read-only Redis clusters.\n- Configurable batch size and sleep intervals for large datasets.\n\n## Installation\n\nTo install `redis-key-analyzer`, use pip:\n\n```bash\npip install redis-key-analyzer\n```\n\n## Usage\n\nYou can use the `redis-key-analyzer` via the command line interface (CLI). Below are the available options:\n\n```bash\nUsage: redis-key-analyzer [OPTIONS]\n\nOptions:\n  --host TEXT          Redis host. Default is 'localhost'.\n  --port INTEGER       Redis port. Default is 6379.\n  --db INTEGER         Redis database. Default is 0.\n  --read-only, -ro     Check read-only cluster.\n  --match, -m TEXT     Redis key pattern. Default is '*'.\n  --batch-size INTEGER Batch size. Default is 1000.\n  --prefix TEXT        Prefixes for key pattern. Example: --prefix 'prefix1 prefix2'.\n  --separator TEXT     Separators for key pattern. Default is ':'.\n  --separator-max-depth INTEGER Max depth for separator. Default is 1.\n  --limit INTEGER      Limit total keys. -1 for no limit. Default is -1.\n  --sleep INTEGER      Sleep seconds between batches. -1 for no sleep. Default is -1.\n  --help               Show this message and exit.\n```\n\nSearch \n\n```bash\nrka --host localhost [--port 6379] [--db 0] [-m '*']\n\n+-------------+--------+-------+---------+---------+-------+--------------+-----------+------------+------------+----------+----------+--------------+\n| pattern     | dtype  |  ttl  | avg_ttl | max_ttl | count | total_memory | memory_hu | memory_avg | memory_max | size_avg | size_max | key(max_ttl) |\n+-------------+--------+-------+---------+---------+-------+--------------+-----------+------------+------------+----------+----------+--------------+\n| my-set      |  set   | NOTTL |    -1   |    -1   |   1   |          272 |  272.0  B |    272     |    272     |    3     |    3     | my-set       |\n| my-list     |  list  | NOTTL |    -1   |    -1   |   1   |          223 |  223.0  B |    223     |    223     |    14    |    14    | my-list      |\n| foos:<*>    | string |  TTL  |   524   |   984   |   3   |          183 |  183.0  B |     61     |     61     |    3     |    3     | foos:123     |\n| my-hash     |  hash  | NOTTL |    -1   |    -1   |   1   |           87 |   87.0  B |     87     |     87     |    2     |    2     | my-hash      |\n| my-zset     |  zset  | NOTTL |    -1   |    -1   |   1   |           83 |   83.0  B |     83     |     83     |    2     |    2     | my-zset      |\n| user.sc:<*> |  hash  | NOTTL |    -1   |    -1   |   1   |           75 |   75.0  B |     75     |     75     |    1     |    1     | user.sc:123  |\n| my-string   | string | NOTTL |    -1   |    -1   |   1   |           61 |   61.0  B |     61     |     61     |    3     |    3     | my-string    |\n+-------------+--------+-------+---------+---------+-------+--------------+-----------+------------+------------+----------+----------+--------------+\n```\n\n## CLI Usage Examples\n### 1) Quick scan (defaults)\n\nScan localhost:6379, DB 0, all keys:\n```bash\nrka\n# same as:\n# rka --host localhost --port 6379 --db 0 --match '*'\n```\n\n### 2) Filter by pattern\n\nOnly analyze keys that match a specific glob pattern (e.g., sessions):\n\n```bash\nrka -m 'session:*'\n```\n\n### 3) Group by prefixes & separators\n\nTell the analyzer which prefixes matter, and how to split keys:\n\n```bash\n# Keys like \"user:123\", \"user:profile:456\", \"order:789\"\nrka --prefix 'order:' --separator ':' --separator-max-depth 1\n```\n- `--separator` ':': split keys on :\n\n- `--separator-max-depth 1`: group at most one level deep, e.g. user:<*>, order:<*>\n\n- `--prefix` 'user order': highlight these prefixes in grouping stats\n\n#### 3.1)  `--separator-max-depth` examples:\n\nAssume the following keys:\n\n```text\ncoupon:MKT-A:1001\ncoupon:MKT-A:1002\ncoupon:MKT-B:2001\ncoupon:MKT-B:2002\n```\nDepth = 1\n\nUse only up to the first : as the grouping prefix.\n\n```bash\nrka --separator ':' --separator-max-depth 1\n```\nAggregated pattern (example):\n```bash\ncoupon:<*>\n```\n\nDepth = 2\n\nUse up to the second : as the grouping prefix.\n\n```bash\nrka --separator ':' --separator-max-depth 2 -m 'coupon:*'\n```\n\nAggregated patterns (example):\n```bash\ncoupon:MKT-A:<*>\ncoupon:MKT-B:<*>\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Redis Key Analyzer is a CLI tool for scanning and analyzing Redis database keys, providing insights into their distribution, type, memory usage, and TTL.",
    "version": "0.1.6",
    "project_urls": {
        "Source": "https://github.com/runnable38/redis-key-analyzer"
    },
    "split_keywords": [
        "redis",
        " pypi",
        " redis keys analyzer"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7bffd5a618162cf1ffc4656041bc9036bb5a7e50409fd636559d88af36aa9d0d",
                "md5": "9eb14298cc665ce35fa789c2a607a3ed",
                "sha256": "1457a7c04ef52a8b320d6b79c2d76fc65ceabac5086b8de8dd60c5a9f2421d7d"
            },
            "downloads": -1,
            "filename": "redis_key_analyzer-0.1.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9eb14298cc665ce35fa789c2a607a3ed",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 12483,
            "upload_time": "2025-09-06T09:19:32",
            "upload_time_iso_8601": "2025-09-06T09:19:32.800380Z",
            "url": "https://files.pythonhosted.org/packages/7b/ff/d5a618162cf1ffc4656041bc9036bb5a7e50409fd636559d88af36aa9d0d/redis_key_analyzer-0.1.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0c54e26071aedad543d6cb7b9c230e556abb9d1eaca2a655908b2405e52beccb",
                "md5": "98bf2d364a911a938d3718e8729b1964",
                "sha256": "0303912f84a7af31e63164a9d4045761a035abea2e0f91c985a94af73e4b6ffc"
            },
            "downloads": -1,
            "filename": "redis-key-analyzer-0.1.6.tar.gz",
            "has_sig": false,
            "md5_digest": "98bf2d364a911a938d3718e8729b1964",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 11463,
            "upload_time": "2025-09-06T09:19:34",
            "upload_time_iso_8601": "2025-09-06T09:19:34.665925Z",
            "url": "https://files.pythonhosted.org/packages/0c/54/e26071aedad543d6cb7b9c230e556abb9d1eaca2a655908b2405e52beccb/redis-key-analyzer-0.1.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-06 09:19:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "runnable38",
    "github_project": "redis-key-analyzer",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "click",
            "specs": []
        },
        {
            "name": "redis",
            "specs": []
        },
        {
            "name": "tqdm",
            "specs": []
        },
        {
            "name": "prettytable",
            "specs": []
        }
    ],
    "lcname": "redis-key-analyzer"
}
        
Elapsed time: 0.50100s