大Key会带来的问题
排查大key方法
开源rdb方式
安装
git clone https://github.com/sripathikrishnan/redis-rdb-tools
cd redis-rdb-tools
sudo python setup.py install
使用范例
rdb -c memory dump-10030.rdb > memory1.csv
redis-cli 原生自带 –bigkeys 方式
$ redis-cli -p 10030 --bigkeys -i 0.1
# Scanning the entire keyspace to find biggest keys as well as
# average sizes per key type. You can use -i 0.1 to sleep 0.1 sec
# per 100 SCAN commands (not usually needed).
[00.00%] Biggest hash found so far '"REDIS_VIRTUAL_STORE_ORDER_ID_INITIALIZER"' with 13 fields
[00.00%] Biggest hash found so far '"REDIS_COUPON_USED_INITIALIZER"' with 3480 fields
[00.00%] Biggest hash found so far '"REDIS_USER_TICKET_INITIALIZER"' with 68017 fields
[00.00%] Biggest string found so far 'THD_INVOKE_RESULT:":com.dianrong.mkts.service.thirdparty.service.CoreServiceRemote::getPlanInfoByPlanId:3513058"' with 5 bytes
[00.00%] Biggest list found so far '"QUEUE_AWARD_NUM_KEY"' with 7 items
-------- summary -------
Sampled 14 keys in the keyspace!
Total key length in bytes is 667 (avg len 47.64)
Biggest string found 'THD_INVOKE_RESULT:":com.dianrong.mkts.service.thirdparty.service.CoreServiceRemote::getPlanInfoByPlanId:3513058"' has 5 bytes
Biggest list found '"QUEUE_AWARD_NUM_KEY"' has 7 items
Biggest hash found '"REDIS_USER_TICKET_INITIALIZER"' has 68017 fields
2 strings with 10 bytes (14.29% of keys, avg size 5.00)
1 lists with 7 items (07.14% of keys, avg size 7.00)
0 sets with 0 members (00.00% of keys, avg size 0.00)
11 hashs with 196712 fields (78.57% of keys, avg size 17882.91)
0 zsets with 0 members (00.00% of keys, avg size 0.00)
可以发现 Biggest hash found so far '"REDIS_USER_TICKET_INITIALIZER"' with 68017 fields 异常的大
删除方法
注意删除超过 maxmemory redis进程挂掉,慎重删除!
127.0.0.1:10030> keys '*REDIS_USER_TICKET_INITIALIZER*'
127.0.0.1:10030> del "\"REDIS_USER_TICKET_INITIALIZER\""