Redis 使用 hotkeys 查看热点数据
Redis 面试 诊断工具 About 1,045 words前置要求
Redis 4.0.3
中新增查看热点数据命令行,使用热点数据必须将内存策略修改为LFU
算法。
查看内存策略
config get maxmemory-policy
输出:
127.0.0.1:6379> config get maxmemory-policy
1) "maxmemory-policy"
2) "noeviction"
查看 key 使用频率
object freq myKey
输出异常信息,需修改内存淘汰策略为LFU
算法。
127.0.0.1:6379> object freq myKey
(error) ERR An LFU maxmemory policy is not selected, access frequency not tracked. Please note that when switching between policies at runtime LRU and LFU data will take some time to adjust.
LFU
Least Frequently Used
:最不经常使用。
Redis
有两种LFU
算法:
volatile-lfu
:设置了过期时间的key
中,进行LFU
淘汰。allkeys-lfu
:所有key
参与LFU
淘汰。
更改内存策略
config set maxmemory-policy allkeys-lfu
查看热点数据
统计时间隔0.1
秒,防止阻塞其他线程。
redis-cli --hotkeys -i 0.1
输出:
root@root:~# redis-cli --hotkeys -i 0.1
# Scanning the entire keyspace to find hot 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%] Hot key 'aaa' found so far with counter 1
-------- summary -------
Sampled 4 keys in the keyspace!
hot key found with counter: 1 keyname: aaa
Views: 6,363 · Posted: 2021-03-20
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...