![](https://i-blog.csdnimg.cn/blog_migrate/7bf48455988b53c71d78bbf49acaa634.png)
前言
redis是一款非常流行的kv数据库,以高性能著称,其高吞吐、低延迟等特性让广大开发者趋之若鹜,每每看到别人发出的redis故障报告都让我产生一种居安思危,以史为鉴的危机感,恰逢今年十一西安烟雨不断,抽时间学习了几个redis监控命令,和大家分享一波。
redis-cli --stat【连续统计】
连续统计可能是实时监控 Redis 实例的鲜为人知但非常有用的功能之一,要启用此功能,请使用redis-cli --stat。
redis-cli --stat 默认每秒输出一条新行,其中包含有用信息和每个采集点的请求次数差异。使用此命令可以轻松了解内存使用情况、客户端连接计数以及有关已连接 Redis 数据库的各种其他统计信息。
可以使用-i修改采样频率,默认值为1秒,如下面这个命令代表每2s采集一次数据:
redis-cli --stat -i 2
------- data ------ --------------------- load -------------------- - child -
keys mem clients blocked requests connections
8890 131.89M 47 0 1705992846 (+0) 2595
8890 131.93M 47 0 1705992897 (+51) 2595
8890 131.93M 47 0 1705992954 (+57) 2595
8890 131.97M 47 0 1705992991 (+37) 2595
8890 131.89M 47 0 1705993043 (+52) 2595
8890 131.97M 47 0 1705993088 (+45) 2595
8890 132.01M 47 0 1705993122 (+34) 2595
8890 132.01M 47 0 1705993168 (+46) 2595
8890 132.01M 47 0 1705993194 (+26) 2595
8890 131.93M 47 0 1705993267 (+73) 2595
redis-cli --bigkeys【统计大key】
这个命令用作键空间分析器,它扫描数据集中的大键,但也提供有关数据集所包含的数据类型的信息。
# redis-cli --bigkeys
# 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 '"hash_big"' with 6 fields
[00.00%] Biggest set found so far '"set_big"' with 6 members
[00.00%] Biggest string found so far '"string_big"' with 979 bytes
[00.00%] Biggest string found so far '"string_big_2"' with 1365 bytes
-------- summary -------
Sampled 5 keys in the keyspace!
Total key length in bytes is 38 (avg len 7.60)
Biggest hash found '"hash_big"' has 6 fields
Biggest string found '"string_big_2"&#