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

  作者: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

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

详情请见: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

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

时间: 2024-08-24 12:09:42

Redis常用命令解析——INFO, MONITOR, SLOWLOG的相关文章

No-sql之redis常用命令

转自:http://blog.csdn.net/nicewuranran/article/details/51793760 No-SQL之Redis 介绍 Redis是一种基于内存存储的key-value高性能存储系统,类似memcached,但是redis支持丰富的数据结构类型,并且其还支持数据持久化到磁盘. Redis is a data structure server. It is open-source, networked, in-memory, and stores keys wi

自学总结redis第二部分(redis常用命令、高级命令特性以及与java代码的结合)

六.redis多数据类型介绍(常用命令) 6.1前提操作 #如果前面的redis环境没搭好,那么可以先暂时在 "http://try.redis.io/"中实践redis命令部分.   #为了测试方便,把redis登录密码暂时撤销   #redis一共分为五种基本数据类型:String,Hash,List,Set,ZSet #所有命令都可以到"http://www.redis.cn/commands.html"  去搜索到. #首先由于redis是一个基于key-v

redis常用命令及高级特性

11.redis常用命令 keys * 返回所有的键 keys my* 模糊匹配 exists key 确认key是否存在 del key expire key time对现有的键设置过期时间[秒为单位] ttl key 查看过期时间,-1代表已过期 move 将当期数据库中的key移到其它数据库当中 select database_name 选择数据库 move key database_name persist key 取消过期时间,此时ttl key返回-1并不代表过期 randomkey

Redis常用命令与高级应用

附: 127.0.0.1:6379> set xiaofei 小飞 OK 127.0.0.1:6379> get xiaofei "\xe5\xb0\x8f\xe9\xa3\x9e" 127.0.0.1:6379> quit [[email protected] redis-2.8.6]# redisc --raw 127.0.0.1:6379> get xiaofei 小飞 127.0.0.1:6379> 5. sorted sets类型和操作 sort

Redis快速起步及Redis常用命令大全

本系列教程内容提要 Java工程师之Redis实战系列教程教程是一个学习教程,是关于Java工程师的Redis知识的实战系列教程,本系列教程均以解决特定问题为目标,使用Redis快速解决在实际生产中的相关问题,为了更方便的与大家一起探讨与学习,每个章节均提供尽可能详细的示例源码及注释,所有示例源码均可在javacourse-redis-in-action找到相关帮助! 本章目标: 什么是Redis Redis数据结构 Redis常用命令 什么是Redis Redis是一个功能强大的非关系型内存数

Redis 常用命令 大全

Redis 常用命令 发现几个很好的 Redis 常用命令汇总大全网页,分享给小伙伴们~ 1.Redis 命令参考 http://redisdoc.com/string/index.html 2.W3Cschool https://www.w3cschool.cn/redis_all_about/redis_all_about-sfc726u6.html 3.Runoob https://www.runoob.com/redis/redis-commands.html 原文地址:https://

Redis常用命令-list-set-zset

Redis常用命令 Redis支持五种数据类型:string(字符串),hash(哈希),list(列表),set(集合)及zset(sorted set:有序集合)等 https://gitee.com/nmwork/RedisUtil 1.   Redis数据类型 1.1.  List类型 1.1.1.   简介 Redis列表是简单的字符串列表,按照插入顺序排序.你可以添加一个元素到列表的头部(左边)或者尾部(右边)一个列表最多可以包含 232 - 1 个元素 (4294967295, 每

redis入门——redis常用命令

redis的常用命令主要分为两个方面.一个是键值相关命令.一个是服务器相关命令 1.键值相关命令 keys * 取出当前所有的key exists name 查看n是否有name这个key del name 删除key name expire confirm 100 设置confirm这个key100秒过期 ttl confirm 获取confirm 这个key的有效时长 select 0 选择到0数据库 redis默认的数据库是0~15一共16个数据库 move confirm 1 将当前数据

Redis - 常用命令操作

常用命令keys:        keys *        查看符合条件的所有keyexists:        exists key    查看key是否存在del:        del key        删除一个keyexpire:        expire key time    设置一个key的过期时间move:        move key basenum    将指定key转移到其他数据库persist:        persist key    移除指定key的过期时