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,有其餘的解析方案嗎?
答: