Redis 热 key

梦莱2年前技术文章724

1、hotkeys

该方案只能针对于 key 的过期淘汰策略为 allkeys-lfu 或者 volatile-lfu 的实例。

-----查看淘汰策略
config get maxmemory-policy
----修改淘汰策略
config set maxmemory-policy volatile-lfu
--查看 hotkey
redis-cli -h r-xxx.redis.rds.aliyuncs.com -p 6379 -a "123456" --hotkeys
redis-cli --hotkeys
查询结果反馈如下:
[root@orcls ~]# redis-cli --hotkeys

# 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).

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.
[root@orcls ~]# redis-cli --hotkeys

# 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).


-------- summary -------

Sampled 7 keys in the keyspace!

补充:LRU 和 LFU 算法区别:

LRU是从满足算法条件的数据中选择空闲时间最长的

LFU是从满足算法条件的数据中选择使用频率最低的

2、monitor

Redis 的 MONITOR 命令能够忠实地打印 Redis 中的所有请求,包括时间信息、Client 信息、命令以及 Key 信息。在发生紧急情况时,可以通过短暂执行 MONITOR 命令并将返回信息输入至文件,在关闭 MONITOR 命令后,对文件中请求进行归类分析,找出这段时间中的热 Key。

注意:由于 MONITOR 命令对 Redis 实例性能消耗较大,非特殊情况不推荐使用 MONITOR 命令。

127.0.0.1:6379> monitor
OK
1684220725.203176 [0 172.16.104.32:38579] "PING"
1684220725.713214 [0 172.16.104.60:55774] "PING"
1684220725.907949 [0 172.16.104.32:38579] "INFO"
1684220726.120256 [0 172.16.104.32:38579] "PUBLISH" "__sentinel__:hello" "172.16.104.32,26379,f798a63e858bff905ca3ae7cdb2a5db16179806b,2,mymaster,172.16.104.32,6379,2"
1684220726.152986 [0 172.16.104.60:55774] "INFO"
1684220726.294286 [0 172.16.104.32:38579] "PING"
1684220726.723099 [0 172.16.104.60:55774] "PING"
1684220727.137292 [0 172.16.104.60:55774] "PUBLISH" "__sentinel__:hello" "172.16.104.60,26379,ed032bf681d56b743e74af1615dc264dc465444c,2,mymaster,172.16.104.32,6379,2"
1684220727.369043 [0 172.16.104.32:38579] "PING"
1684220727.742207 [0 172.16.104.60:55774] "PING"
1684220728.155509 [0 172.16.104.32:38579] "PUBLISH" "__sentinel__:hello" "172.16.104.32,26379,f798a63e858bff905ca3ae7cdb2a5db16179806b,2,mymaster,172.16.104.32,6379,2"
1684220728.384930 [0 172.16.104.32:38579] "PING"
1684220728.770192 [0 172.16.104.60:55774] "PING"
1684220729.158312 [0 172.16.104.60:55774] "PUBLISH" "__sentinel__:hello" "172.16.104.60,26379,ed032bf681d56b743e74af1615dc264dc465444c,2,mymaster,172.16.104.32,6379,2"
1684220729.407570 [0 172.16.104.32:38579] "PING"
1684220729.819311 [0 172.16.104.60:55774] "PING"
1684220730.196226 [0 172.16.104.32:38579] "PUBLISH" "__sentinel__:hello" "172.16.104.32,26379,f798a63e858bff905ca3ae7cdb2a5db16179806b,2,mymaster,172.16.104.32,6379,2"
1684220730.495966 [0 172.16.104.32:38579] "PING"
1684220730.837517 [0 172.16.104.60:55774] "PING"
1684220731.194453 [0 172.16.104.60:55774] "PUBLISH" "__sentinel__:hello" "172.16.104.60,26379,ed032bf681d56b743e74af1615dc264dc465444c,2,mymaster,172.16.104.32,6379,2"
^C
(venv) [root@orcls demo]# ^C


相关文章

数据湖技术之iceberg(五)Hive与Iceberg整合

数据湖技术之iceberg(五)Hive与Iceberg整合

1.  版本支持约束条件Iceberg就是一种表格式,支持使用Hive对Iceberg进行读写操作,但是对Hive的版本有要求,如下:Iceberg 与 Hive 2.x 和 Hive 3....

Ubuntu 网卡启动及配置

Ubuntu 网卡启动及配置

问题分析打开虚拟机后发现没有网卡网络。查看网卡信息sudo ip link set ens33 up1得到本机的所有网卡信息,例如我这边网卡为ens33启动网卡启动网卡后发现依然网卡没有IP地址。配置...

keycloak部署和使用

keycloak部署和使用

简介Keycloak是一个开源软件产品,旨在为现代的应用程序和服务,提供包含身份管理和访问管理功能的单点登录工具。截至2018年3月,红帽公司负责管理这一JBoss社区项目,并将其作为他们RH-SSO...

开源大数据集群部署(六)Keytab文件生成

开源大数据集群部署(六)Keytab文件生成

1、 创建keytab文件除了使用明文密码登录之外,Kerberos还可以使用keytab密码文件登陆,现在为testcuser创建它的keytab文件ipa-getkeytab -s ipa.hdp...

ACOS无数据告警实践

ACOS无数据告警实践

1.说明在实现数据监控的过程中告警能力无疑是重中之重,无数据告警亦是告警能力中重要的场景,这里我们聊聊关于无数据一些场景和实践方法。2.无数据可能场景对于运维监控平台来说无数据是一个比较复杂的情况,从...

查看 Redis 不过期 key

查看 Redis 不过期 key

一、使用 Rdbtools 工具包使用 Rdbtools 工具包通过分析备份 rdb 文件,可以查看期间大 key 情况及过期时间情况。输出 csv 文档列信息情况详见下方附件--安装 rdb 工具包...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。