1. 程式人生 > >統計redis大key信息(前topN)

統計redis大key信息(前topN)

gin create cape desc dump encoding app nal 下載鏈接

相關包下載鏈接

https://github.com/sripathikrishnan/redis-rdb-tools/releases
https://pypi.org/project/python-lzf/
https://pypi.python.org/simple/redis/

安裝

pip install python-lzf-0.2.4.tar.gz
pip install redis-2.10.6.tar.gz
pip install rdbtools-0.1.12.tar.gz

解析redis RDB文件

建議放在其他測試環境執行,避免對生產主機的資源有影響
通過一下模擬一些大key
cat /root/test.txt | /dbdata/redis/app1/redis4010/bin/redis-cli -h 5.5.5.102 -p 6379 -a abc123 --pipe
cat /root/test2.txt | /dbdata/redis/app1/redis4010/bin/redis-cli -h 5.5.5.102 -p 6379 -a abc123 --pipe
rdb.py -c memory /dbdata/dumpdir/dump.rdb > /dbdata/dumpdir/memory.csv

刪除掉表頭信息

sed -i ‘1d‘ memory.csv
即(database,type,key,size_in_bytes,encoding,num_elements,len_largest_element)

在mysql中創建表

CREATE TABLE memory (
database int(128) DEFAULT NULL,
type varchar(128) DEFAULT NULL,
KEY varchar(128) not NULL,
size_in_bytes bigint(20) DEFAULT NULL,
encoding varchar(128) DEFAULT NULL,
num_elements

bigint(20) DEFAULT NULL,
len_largest_element varchar(128) DEFAULT NULL,
PRIMARY KEY (KEY));

導入到mysql中

load data infile ‘/dbdata/dumpdir/memory.csv‘
into table memory
fields terminated by ‘,‘ optionally enclosed by ‘"‘ escaped by ‘"‘
lines terminated by ‘\n‘;

查看top N的big keys信息

select * from memory order by size_in_bytes desc limit N;

統計redis大key信息(前topN)