pip install rdbtools python-lzf
或者python
git clone https://github.com/sripathikrishnan/redis-rdb-tools cd redis-rdb-tools sudo python setup.py install
--help
usage: usage: rdb [options] /path/to/dump.rdb Example : rdb --command json -k "user.*" /var/redis/6379/dump.rdb positional arguments: dump_file RDB Dump file to process optional arguments: -h, --help show this help message and exit -c CMD, --command CMD Command to execute. Valid commands are json, diff, justkeys, justkeyvals, memory 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 -o NOT_KEYS, --not-key NOT_KEYS Keys Not 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 -b BYTES, --bytes BYTES Limit memory output to keys greater to or equal to this value (in bytes) -l LARGEST, --largest LARGEST Limit memory output to only the top N keys (by size) -e {raw,print,utf8,base64}, --escape {raw,print,utf8,base64} Escape strings to encoding: raw (default), print, utf8, or base64. -x, --no-expire With protocol command, remove expiry from all keys -a N, --amend-expire N With protocol command, add N seconds to key expiry time
参数解析git
[{"int":"1"}]
'^users_\d+$'
下面看一下一些常见用法:github
rdb --command memory dump.rdb > memory.csv
生成 CSV 格式的内存报告。包含的列有:
数据库 ID,数据类型,key,内存使用量(byte),编码。内存使用量包含 key、value 和其余值,结果:web
database,type,key,size_in_bytes,encoding,num_elements,len_largest_element,expiry 0,set,fruit,252,hashtable,2,6, 0,hash,webset,81,ziplist,1,13, 0,string,baiduyun,64,string,5,5, 0,list,languages,161,quicklist,2,6, 0,sortedset,page_rank,80,ziplist,1,9
# 使用这个命令会将存储的 int 值显示为 json 的字符串 > rdb -c json --db 2 --type hash --key "a.*" /var/redis/6379/dump.rdb [{},{ "aroma":{"pungent":"vinegar","putrid":"rotten eggs","floral":"roses"}}]
> rdb --command diff /var/redis/6379/dump1.rdb | sort > dump1.txt > rdb --command diff /var/redis/6379/dump2.rdb | sort > dump2.txt # 使用 diff 软件查看 diff > kdiff3 dump1.txt dump2.txt
> redis-memory-for-key person:1 > redis-memory-for-key -s localhost -p 6379 -a mypassword person:1 Key person:1 Bytes 111 Type hash Encoding ziplist Number of Elements 2 Length of Largest Element 8 # hash 中占用内存最大的那个 value 的占用字节数
内存报告的精确度如何?正则表达式
答:最多有 10% 的偏差redis
存储了一个二进制 binary 数据,可是输出的时候是乱码,不可读,怎么处理?shell
答:能够使用 -e 命令先输出 base64 编码的字符串,而后程序中解码以后使用数据库
这个工具能解析哪一个版本的 rdb 文件?express
答:2~6 版本json
我不想用 python,有其余的解析方案吗?
答: