Redis 热 key

梦莱1年前技术文章419

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


相关文章

python-序列化和反序列化

1、为什么要序列化内存中的字典、列表、集合以及各种对象,如何保存到一个文件中?如果是自己定义的类的实例,如何保存到一个文件中?如何从文件中读取数据,并让它们在内存中再次恢复成自己对应的类的实例?要设计...

LINUX 安全运维-用户密码

密码策略linux作为一个多用户的系统,我们还是不可避免的会去新增很多用户,我们不能保证每一个用户具有很好的安全意识,所以只能在用户的密码以及用户的远程访问上做一些限制,我们先介绍Linux用户密码策...

greenplum扩容

一、纵向扩展1、执行命令,生成参数文件[gpadmin@gw_mdw1 ~]$ gpexpand -f seg_hosts -D test 20190327:23:18:01:007122 gpex...

hdfs数据迁移

hdfs数据迁移

通过使用distcp进行数据全量迁移DistCp(分布式拷贝)是用于大规模集群内部和集群之间拷贝的工具。 它使用Map/Reduce实现文件分发,错误处理和恢复,以及报告生成。 它把文件和目录的列表作...

Hadoop3.2.4纠删码实操(三)

Hadoop3.2.4纠删码实操(三)

1、纠删码实操1.在HDFS中建立以下三个目录,并都设置为XOR-2-1-1024k策略。[root@hd2 hadoop]# hadoop fs -mkdir /ec_xor_s SLF4J: C...

Elasticsearch查询慢日志配置

shard级别的查询慢日志会将慢查询(查询和获取阶段)记录到elasticsearch_cluster_index_search_slowlog.log日志中。设置查询慢日志各种级别下的阀值,同时也支...

发表评论    

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