慢查询,顾名思义就是比较慢的查询。
在慢查询的定义中,统计比较慢的时间段指的是命令执行这个步骤。没有慢查询,并不表示客户端没有超时问题,有可能网络传输有延迟,也有可能排队的命令比较多。
因为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
本文详细解释了Redis中的慢查询概念,其在命令执行中的影响,以及如何通过配置文件和configset命令调整慢查询设置,以防止级联阻塞并优化性能。
1477

被折叠的 条评论
为什么被折叠?



