RdbTools是一个因为分析Redis dump.rdb文件的工具,有如下功能:python
经过pip安装git
pip install rdbtools
源码安装github
git clone https://github.com/sripathikrishnan/redis-rdb-tools cd redis-rdb-tools sudo python setup.py install
命令一览:正则表达式
[root@virt]# rdb --help Usage: rdb [options] /path/to/dump.rdb Example : rdb --command json -k "user.*" /var/redis/6379/dump.rdb Options: -h, --help show this help message and exit -c FILE, --command=FILE Command to execute. Valid commands are json, diff, and protocol -f FILE, --file=FILE Output file -n DBS, --db=DBS Database Number. Multiple databases can be provided. If not specified, all databases will be included. -k KEYS, --key=KEYS Keys to export. This can be a regular expression -t TYPES, --type=TYPES Data types to include. Possible values are string, hash, set, sortedset, list. Multiple typees can be provided. If not specified, all data types will be returned
解析dump文件并经过标准输出JSON:redis
rdb --command json /var/redis/6379/dump.rdb
只处理某些key(支持正则表达式):数据库
rdb --command json --key "user.*" /var/redis/6379/dump.rdb
只处理已a开始在db2的hash结构:express
rdb --command json --db 2 --type hash --key "a.*" /var/redis/6379/dump.rdb
使用-c memory
命令生成每一个key内存使用量的csv报告json
rdb -c memory /var/redis/6379/dump.rdb > memory.csv
生成的csv格式以下:数据库编号,数据类型,key名,字节表示的内存使用量和编码。 内存使用量包括key,value和其余杂项。 注意内存使用量是预估的。一般实际内存使用量会比报告中要高。ide
内存报告能够帮助咱们找到应用程序逻辑形成的内存泄漏,也能够帮助咱们优化redis内存使用。工具
redis-memory-for-key person:1 redis-memory-for-key -s localhost -p 6379 -a mypassword person:1