0

0

Redis常用命令解析INFO,MONITOR,SLOWLOG

php中文网

php中文网

发布时间:2016-06-07 16:11:04

|

1811人浏览过

|

来源于php中文网

原创

作者:zhanhailiang 日期:2014-12-02 1. info info指令返回服务器相关信息,包括: server: General information about the Redis server clients: Client connections section memory: Memory consumption related information persistence: RDB and AOF r

  作者:zhanhailiang 日期:2014-12-02

1. info

info指令返回服务器相关信息,包括:

  • server: General information about the Redis server
  • clients: Client connections section
  • memory: Memory consumption related information
  • persistence: RDB and AOF related information
  • stats: General statistics
  • replication: Master/slave replication information
  • cpu: CPU consumption statistics
  • commandstats: Redis command statistics
  • cluster: Redis Cluster section
  • keyspace: Database related statistics

    其本身支持定制返回列表:

    [root@~]# redis-cli info
    [root@~]# redis-cli info default
    [root@~]# redis-cli info all

    详情请见:http://www.redis.cn/commands/info.html

    2. MONITOR

    MONITOR是一个调试命令,返回服务器处理的每一个命令,它能帮助我们了解在数据库上发生了什么操作。共有3种操作方法:

    [root@~]# redis-cli monitor
    OK
    1417532512.619715 [0 127.0.0.1:55043] "REPLCONF" "ACK" "6623624"
    [root@~]# telnet 127.0.0.1 6379
    Trying 127.0.0.1...
    Connected to 127.0.0.1.
    Escape character is '^]'.
    monitor
    +OK
    +1417532567.733458 [0 127.0.0.1:55043] "REPLCONF" "ACK" "6623708"
    +1417532568.735936 [0 127.0.0.1:55043] "REPLCONF" "ACK" "6623708"
    quit
    +OK
    Connection closed by foreign host.
    [root@~]# redis-cli 
    127.0.0.1:6379> monitor
    OK
    1417532590.785487 [0 127.0.0.1:55043] "REPLCONF" "ACK" "6623736"

    由于MONITOR命令返回服务器处理的所有的命令, 所以在性能上会有一些消耗。使用官方的压测工具测试结果如下

    在不运行MONITOR命令的情况下,benchmark的测试结果:

    [root@~/software/redis-2.8.17]# src/redis-benchmark -c 10 -n 100000 -q
    PING_INLINE: 51020.41 requests per second
    PING_BULK: 50607.29 requests per second
    SET: 37257.82 requests per second
    GET: 49800.80 requests per second
    INCR: 38699.69 requests per second
    LPUSH: 38910.51 requests per second
    LPOP: 39277.30 requests per second
    SADD: 54614.96 requests per second
    SPOP: 51948.05 requests per second
    LPUSH (needed to benchmark LRANGE): 38819.88 requests per second
    LRANGE_100 (first 100 elements): 20112.63 requests per second
    LRANGE_300 (first 300 elements): 9025.27 requests per second
    LRANGE_500 (first 450 elements): 6836.67 requests per second
    LRANGE_600 (first 600 elements): 5406.28 requests per second
    MSET (10 keys): 19394.88 requests per second

    在运行MONITOR命令的情况下,benchmark的测试结果: (redis-cli monitor > /dev/null):

    [root@~/software/redis-2.8.17]# src/redis-benchmark -c 10 -n 100000 -q
    PING_INLINE: 42211.91 requests per second
    PING_BULK: 42936.88 requests per second
    SET: 26143.79 requests per second
    GET: 33990.48 requests per second
    INCR: 26553.37 requests per second
    LPUSH: 27337.34 requests per second
    LPOP: 27225.70 requests per second
    SADD: 30459.95 requests per second
    SPOP: 39494.47 requests per second
    LPUSH (needed to benchmark LRANGE): 26315.79 requests per second
    LRANGE_100 (first 100 elements): 22055.58 requests per second
    LRANGE_300 (first 300 elements): 8104.38 requests per second
    LRANGE_500 (first 450 elements): 6371.05 requests per second
    LRANGE_600 (first 600 elements): 5031.95 requests per second
    MSET (10 keys): 14861.05 requests per second

    可以看到各项指标基本都有所下降。

    万兴爱画
    万兴爱画

    万兴爱画AI绘画生成工具

    下载

    详情请见:http://www.redis.cn/commands/monitor.html

    3. SLOWLOG

    通过SLOWLOG可以读取慢查询日志。

    使用SLOWLOG LEN就可以获取当前慢日志长度。

    [root@~/software/redis-2.8.17]# redis-cli 
    127.0.0.1:6379> slowlog len
    (integer) 28

    使用SLOWLOG GET就可以获取所有慢日志。

    127.0.0.1:6379> slowlog get 
     1) 1) (integer) 27
        2) (integer) 1417531320
        3) (integer) 24623
        4) 1) "info"

    其中,各项指标表示:

    • A unique progressive identifier for every slow log entry.
    • The unix timestamp at which the logged command was processed.
    • The amount of time needed for its execution, in microseconds(注意,microseconds翻译成微秒,而不是毫秒).
    • The array composing the arguments of the command.

      使用SLOWLOG GET N就可以获取最近N条慢日志。

      127.0.0.1:6379> slowlog get 2
      1) 1) (integer) 27
         2) (integer) 1417531320
         3) (integer) 24623
         4) 1) "info"
      2) 1) (integer) 26
         2) (integer) 1417528379
         3) (integer) 21363
         4) 1) "get"
            2) "user:score"

      使用SLOWLOG RESET命令重置慢日志。一旦执行,将丢失以前的所有慢日志。

      127.0.0.1:6379> slowlog reset

热门AI工具

更多
DeepSeek
DeepSeek

幻方量化公司旗下的开源大模型平台

豆包大模型
豆包大模型

字节跳动自主研发的一系列大型语言模型

通义千问
通义千问

阿里巴巴推出的全能AI助手

腾讯元宝
腾讯元宝

腾讯混元平台推出的AI助手

文心一言
文心一言

文心一言是百度开发的AI聊天机器人,通过对话可以生成各种形式的内容。

讯飞写作
讯飞写作

基于讯飞星火大模型的AI写作工具,可以快速生成新闻稿件、品宣文案、工作总结、心得体会等各种文文稿

即梦AI
即梦AI

一站式AI创作平台,免费AI图片和视频生成。

ChatGPT
ChatGPT

最最强大的AI聊天机器人程序,ChatGPT不单是聊天机器人,还能进行撰写邮件、视频脚本、文案、翻译、代码等任务。

相关专题

更多
C++ 设计模式与软件架构
C++ 设计模式与软件架构

本专题深入讲解 C++ 中的常见设计模式与架构优化,包括单例模式、工厂模式、观察者模式、策略模式、命令模式等,结合实际案例展示如何在 C++ 项目中应用这些模式提升代码可维护性与扩展性。通过案例分析,帮助开发者掌握 如何运用设计模式构建高质量的软件架构,提升系统的灵活性与可扩展性。

14

2026.01.30

c++ 字符串格式化
c++ 字符串格式化

本专题整合了c++字符串格式化用法、输出技巧、实践等等内容,阅读专题下面的文章了解更多详细内容。

9

2026.01.30

java 字符串格式化
java 字符串格式化

本专题整合了java如何进行字符串格式化相关教程、使用解析、方法详解等等内容。阅读专题下面的文章了解更多详细教程。

12

2026.01.30

python 字符串格式化
python 字符串格式化

本专题整合了python字符串格式化教程、实践、方法、进阶等等相关内容,阅读专题下面的文章了解更多详细操作。

4

2026.01.30

java入门学习合集
java入门学习合集

本专题整合了java入门学习指南、初学者项目实战、入门到精通等等内容,阅读专题下面的文章了解更多详细学习方法。

20

2026.01.29

java配置环境变量教程合集
java配置环境变量教程合集

本专题整合了java配置环境变量设置、步骤、安装jdk、避免冲突等等相关内容,阅读专题下面的文章了解更多详细操作。

18

2026.01.29

java成品学习网站推荐大全
java成品学习网站推荐大全

本专题整合了java成品网站、在线成品网站源码、源码入口等等相关内容,阅读专题下面的文章了解更多详细推荐内容。

19

2026.01.29

Java字符串处理使用教程合集
Java字符串处理使用教程合集

本专题整合了Java字符串截取、处理、使用、实战等等教程内容,阅读专题下面的文章了解详细操作教程。

3

2026.01.29

Java空对象相关教程合集
Java空对象相关教程合集

本专题整合了Java空对象相关教程,阅读专题下面的文章了解更多详细内容。

6

2026.01.29

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
进程与SOCKET
进程与SOCKET

共6课时 | 0.4万人学习

Redis+MySQL数据库面试教程
Redis+MySQL数据库面试教程

共72课时 | 6.5万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号