分析rdb文件的工具
安裝
git clone https://github.com/sripathikrishnan/redis-rdb-tools.git
sudo pip install --upgrade pip
sudo pip install python-lzf
分析以n開頭的key
rdb --command justkeyvals --key "n*" /home/kou/redis_tar/redis-3.0-annotated/src/dump.rdb[kou@python ~]$ od -c /home/kou/redis_tar/redis-3.0-annotated/src/dump.rdb
0000000 R E D I S 0 0 0 6 376 \0 \0 004 n a m
0000020 e 005 h o d g e 377 004 | 313 025 = G % 310
0000040
json格式解析并輸出
[kou@python ~]$ rdb --command json /home/kou/redis_tar/redis-3.0-annotated/src/dump.rdb
[{
"name":"hodge"}]
指定數據庫,類型,格式,key
rdb -c json --db 2 --type hash --key "a.*"
生成內存報告
[kou@python ~]$ rdb -c memory /home/kou/redis_tar/redis-3.0-annotated/src/dump.rdb
database,type,key,size_in_bytes,encoding,num_elements,len_largest_element,expiry
0,string,name,56,string,5,5,
查找單鍵使用的內存
redis-memory-for-key -s localhost -p 6379 -a mypassword person:1
RDB文件轉換為Redis協議流protocol
rdb --c protocol
您可以將輸出通過管道傳輸到netcat并重新導入數據的子集。例如,如果要將數據分片到兩個Redis實例中,則可以使用–key標志選擇數據的子集,然后將輸出傳遞給正在運行的Redis實例以加載該數據。閱讀Redis Mass Insert以獲得更多信息。
當輸出打印協議時,該–escape選項可與一起使用printable或utf8避免使用不可打印/控制字符。
比較RDB文件
> rdb --command diff /var/redis/6379/dump1.rdb | sort > dump1.txt
> rdb --command diff /var/redis/6379/dump2.rdb | sort > dump2.txt
然后,運行您喜歡的差異程序> kdiff3 dump1.txt dump2.txt
分析結果
[kou@python ~]$ rdb --command justkeyvals --key "n*" /home/kou/redis_tar/redis-3.0-annotated/src/dump.rdbname hodge