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
相关推荐
fe7tQnVan18 分钟前
MyBatis-动态sql与高级映射
数据库·sql·mybatis
计算机安禾20 分钟前
【数据结构与算法】第28篇:平衡二叉树(AVL树)
开发语言·数据结构·数据库·线性代数·算法·矩阵·visual studio
道清茗2 小时前
【MySQL知识点问答题】高级复制技术
数据库·mysql
IT邦德2 小时前
Oracle备份恢复概览
数据库·oracle
User_芊芊君子2 小时前
别再乱用 ArrayList 了!这 4 个隐藏坑,90% 的 Java 开发者都踩过
android·java·数据库
xcLeigh2 小时前
IoTDB Java 原生 API 实战:SessionPool 从入门到精通
java·开发语言·数据库·api·iotdb·sessionpool
必胜刻2 小时前
Redis分布式锁讲解
数据库·redis·分布式
gjc5922 小时前
零基础OceanBase数据库入门(6):连接OB集群
数据库·oceanbase
2601_954023662 小时前
Review and Installation Guide: Meminz - Download Software Landing Page Theme
数据库·seo·wordpress·gpl
slarymusic2 小时前
redis的下载和安装详解
数据库·redis·缓存