# Specify the server verbosity level.
# This can be one of:
# debug (a lot of information, useful for development/testing)
# verbose (many rarely useful info, but not a mess like the debug level)
# notice (moderately verbose, what you want in production probably)
# warning (only very important / critical messages are logged)
loglevel notice
# Specify the log file name. Also the empty string can be used to force
# Redis to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
logfile “”
慢查询日志存储于内存,读写速度快,对整体性能没什么影响。
################################## 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
可以通过修改配置文件或者直接在交互模式下,交互模式下使用CONFIG SET动态修改:
127.0.0.1:6379>CONFIG SET slowlog-log-slower-than 10000
127.0.0.1:6379>CONFIG SET slowlog-max-len 128
查询慢查询日志:
--打印所有的慢查询日志
127.0.0.1:6379> SLOWLOG GET
1) 1) (integer) 19 --日志唯一标识符
2) (integer) 1592818337 --命令执行的UNIX时间戳
3) (integer) 12111 --命令执行时间(微秒)
4) 1) "scan" --执行的命令及参数
2) "0"
3) "MATCH"
4) "*"
5) "COUNT"
6) "10000"
--打印指定数量的慢查询条目
127.0.0.1:6379> SLOWLOG GET 2
1) 1) (integer) 19
2) (integer) 1592818337
3) (integer) 12111
4) 1) "scan"
2) "0"
3) "MATCH"
4) "*"
5) "COUNT"
6) "10000"
2) 1) (integer) 12
2) (integer) 1578468109
3) (integer) 28051
4) 1) "PFADD"
2) "total_online_counter"
3) "oLtGl5A3EQt5CWmbnf_s0BXoFG7g"
清空慢查询日志(慢查询日志遵循先进先出缓存算法(FIFO)):
127.0.0.1:6379> slowlog len
(integer) 2
127.0.0.1:6379> slowlog reset
OK
127.0.0.1:6379> slowlog len
(integer) 0