redis.conf 慢日志配置
################################## SLOW LOG ###################################
# The Redis Slow Log is a system to log queries that exceeded a specified
# execution time. The execution time does not include the I/O operations
# like talking with the client, sending the reply and so forth,
# but just the time needed to actually execute the command (this is the only
# stage of command execution where the thread is blocked and can not serve
# other requests in the meantime).
#
# You can configure the slow log with two parameters: one tells Redis
# what is the execution time, in microseconds, to exceed in order for the
# command to get logged, and the other parameter is the length of the
# slow log. When a new command is logged the oldest one is removed from the
# queue of logged commands.
# 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
常用指令:
1、设置slowlog的执行耗时阈值
127.0.0.1:6379> config set slowlog-log-slower-than 1000
OK
2、查看slowlog执行耗时的阈值
127.0.0.1:6379> config get slowlog-log-slower-than
1) "slowlog-log-slower-than"
2) "10000"
3、设置slowlog保存数量的阈值
127.0.0.1:6379> config set slowlog-max-len 1024
OK
4、查看slowlog保存数量的阈值
127.0.0.1:6379> config get slowlog-max-len
1) "slowlog-max-len"
2) "1024"
5、查看slowlog的数量
127.0.0.1:6379> slowlog len
(integer) 1024
6、查询slowlog
![](https://img-blog.csdnimg.cn/20210401164158321.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl8zOTAzNTEyMA==,size_16,color_FFFFFF,t_70)
7、清除slowlog记录
127.0.0.1:6379> slowlog reset
OK