统计redis大key信息(前topN)

相关包下载链接

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;

转载于:https://www.cnblogs.com/imdba/p/10116500.html

你可能感兴趣的:(统计redis大key信息(前topN))