redis慢查询设置和查看

慢查询,顾名思义就是比较慢的查询。

在慢查询的定义中,统计比较慢的时间段指的是命令执行这个步骤。没有慢查询,并不表示客户端没有超时问题,有可能网络传输有延迟,也有可能排队的命令比较多。

因为Redis中命令执行的排队机制,慢查询会导致其他命令的级联阻塞,所以当客户端出现请求超时的时候,需要检查该时间点是否有慢查询,从而分析出由于慢查询导致的命令级联阻塞。

慢查询设置

在Redis中有两种修改配置的方法,一种是修改配置文件,另一种是使用config set命令动态修改

命令动态设置

复制代码
//这里使用config set

//slowlog-log-slower-than默认是10000微秒,
config set slowlog-log-slower-than 20000
//slowlog-max-len默认是128,指定服务器最多保存多少条慢查询日志
config set slowlog-max-len 1000
//对启动 Redis 服务器时所指定的 redis.conf 文件进行改写
config rewrite

通过配置文件设置

在redis.conf中配置,重启Redis实例来生效

复制代码
# The following time is expressed in microseconds, so 1000000 is equivalent
# to one second. Note that a negative number disables the slow log, while
# a value of zero forces the logging of every command.
slowlog-log-slower-than 10000

# There is no limit to this length. Just be aware that it will consume memory.
# You can reclaim memory used by the slow log with SLOWLOG RESET.
slowlog-max-len 128

查看慢查询

复制代码
//查看当前慢查询记录有多少条
SLOWLOG len

//列出当前所有慢查询
SLOWLOG get

//列出慢查询的前3条
SLOWLOG get 3
相关推荐
神王宝宝 王者小学10 小时前
HBase: 看上去很美
大数据·数据库·hbase
io无心10 小时前
Shardingsphere5分库分表
数据库·mysql
wWYy.11 小时前
Mysql:主键索引 唯一索引 普通索引 前缀索引
数据库·mysql
宝杰X711 小时前
Android Room3 多平台数据库
android·数据库
sky_81061315 小时前
Oracle ERP 各模块业务管理功能及底层表说明
数据库·oracle
YMatrix 官方技术社区16 小时前
CittaBase vs. Neo4j :原生图性能实测与混合检索实践
数据库·功能测试·ymatrix
闲猫17 小时前
LangChain / Integrations / Integrations by component / Tool
java·数据库·langchain
xqqxqxxq17 小时前
SQL 连接查询技术笔记
数据库·笔记·sql
消失的旧时光-194318 小时前
第六篇:Redis Hash——一个用户对象应该保存成 JSON,还是保存成 Hash?
redis·json·哈希算法
Databend18 小时前
从万亿级大模型到全线应用:Databend Cloud 助力头部 AI 企业构建全链路 Trace 数据管道
大数据·数据库·sql