Redis-慢查询

慢查询指的是redis命令的执行时间,不包括网络传输和排队时间。

Redis配置文件redis.conf中描述慢查询相关的选项在SLOW LOG部分

################################## 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 get及config set来查询和修改,config rewrite可以写入配置文件。此外,slowlog命令还可以完成一些慢查询日志相关的其它操作。

# 命令执行超过多少微秒就记录慢查询日志(1秒=1000毫秒=1000000微秒)
127.0.0.1:6379> CONFIG GET slowlog-log-slower-than
1) "slowlog-log-slower-than"
2) "10000"
# 慢查询日志保存的最大条数
127.0.0.1:6379> config get slowlog-max-len
1) "slowlog-max-len"
2) "128"
# 获取慢查询日志列表当前长度
127.0.0.1:6379> slowlog len
(integer) 0
# 获取慢查询
127.0.0.1:6379> slowlog get
# 重置慢查询
127.0.0.1:6379> slowlog reset
OK

一条慢查询日志包括4个属性:日志id命令执行的时间戳命令耗时命令和参数

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Redis 客户端执行命令分四个部分: 发送命令 命令排队 命令执行 返回结果 Redis 的慢查询只统计步奏3)...
    非典型程序员阅读 6,586评论 0 2
  • 本文将从Redis的基本特性入手,通过讲述Redis的数据结构和主要命令对Redis的基本能力进行直观介绍。之后概...
    kelgon阅读 61,532评论 23 625
  • NOSQL类型简介键值对:会使用到一个哈希表,表中有一个特定的键和一个指针指向特定的数据,如redis,volde...
    MicoCube阅读 9,514评论 2 27
  • 转载地址:http://gnucto.blog.51cto.com/3391516/998509 Redis与Me...
    Ddaidai阅读 21,527评论 0 82
  • 远处的天边,透着浓重的蓝紫色,密密麻麻的星星灿烂地铺开,如同女人脸颊上漂亮的雀斑。温柔的灯光低低地压着湖面,挑逗着...
    桃子满满阅读 1,774评论 0 0

友情链接更多精彩内容