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