Collection of some useful Redis tools. Currently analyze
and delete
.
npm install -g redis-toolkit
> rt analyze -s 100 --patterns 'user:* client:*'
╔════════════╤═══════╤═════════╤═══════════════╤═════════╤═══════════╗
║ Key │ Count │ % of DB │ Size in Bytes │ % of DB │ Mean Size ║
╟────────────┼───────┼─────────┼───────────────┼─────────┼───────────╢
║ /user:*/ │ 81 │ 81.00 │ 14542 │ 40.17 │ 179.53 ║
╟────────────┼───────┼─────────┼───────────────┼─────────┼───────────╢
║ /client:*/ │ 8 │ 8.00 │ 530 │ 1.46 │ 66.25 ║
╟────────────┼───────┼─────────┼───────────────┼─────────┼───────────╢
║ other keys │ 11 │ 11.00 │ 21131 │ 58.37 │ 1921.00 ║
╚════════════╧═══════╧═════════╧═══════════════╧═════════╧═══════════╝
> rt delete --pattern 'user:worker:*'
successfully deleted 43 keys matching pattern "user:worker:*"
Usage: rt [global flags] <command> [command flags]
global flags:
-h --host : string
Redis Host (default localhost)
-p --port : number
Redis Port (default 6379)
analyze command flags:
-s --sample-size : number
Number of keys to analyze
-b --batch-size : number
Size of batch (default: 100)
--patterns : string
one or more key patterns to analyze
delete command flags:
--pattern : pattern
key pattern to delete
search command flags:
--pattern : pattern
key pattern to delete
Specifies Redis Host to connect to. default: localhost
Specifies Redis Port to connect to. default: 6379
Samples <--sample-size> keys matching <--patterns> using randomkey and measures the size of each pattern.
Number of keys to sample. Obviously the more keys the better the confidence level. There are plenty of sample size calculator out there, like this.
Uses the redis client batch command. default: 100
List of one or more key patterns to analyze. default: analyzes the pattern key_prefix:*
Scans the DB and deletes the keys that match the pattern. The delete is done asynchronously using unlinks.
Scans the DB <--batch-size> at a time. default: 1000
Pattern to find.
Scans the DB and finds the keys that match the pattern.
Scans the DB <--batch-size> at a time. default: 1000
Pattern to find.
This being my first open source node project I'd really appreciate any feedback, PR's, or suggestions to improve this CLI 😊