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
相关推荐
cyber_两只龙宝16 分钟前
【MySQL】MySQL主从复制架构
linux·运维·数据库·mysql·云原生·架构
D.不吃西红柿16 分钟前
【无标题】
数据库·database·ai编程·数据库设计
Dylan~~~19 分钟前
PostgreSQL 数据库性能问题定位完全指南
数据库·postgresql
原来是猿23 分钟前
MySQL数据库基础
数据库
阿奇__26 分钟前
前端下拉数据缓存策略
缓存·vue
江不清丶28 分钟前
Text-to-SQL实战:从自然语言到数据库查询的智能数据分析Agent设计
数据库·sql·ai·数据分析
初次攀爬者37 分钟前
Redis与数据库的数据一致性方案解析
数据库·redis·分布式
橘颂TA1 小时前
【MySQL】内置函数
数据库·mysql
EAIReport1 小时前
MongoDB、Redis、HBase 三大NoSQL数据库:核心区别与选型指南
redis·mongodb·hbase
八月瓜科技1 小时前
擎策·知海全球专利数据库 凭差异化优势 筑科技创新检索壁垒
大数据·数据库·人工智能·科技·深度学习·机器人