1 slowlog是什么
redis的slowlog是redis用于记录记录慢查询执行时间的日志系统。由于slowlog只保存在内存中,因此slowlog的效率很高,完全不用担心会影响到redis的性能。Slowlog是Redis从2.2.12版本引入的一条命令。
2 slowlog设置
参考 http://redis.readthedocs.org/en/latest/server/slowlog.html
slowlog有两种设置方式:
2.1 redis.conf设置
在redis.conf中有关于slowlog的设置:
1 2 |
|
其中slowlog-log-slower-than表示slowlog的划定界限,只有query执行时间大于slowlog-log-slower-than的才会定义成慢查询,才会被slowlog进行记录。slowlog-log-slower-than设置的单位是微妙,默认是10000微妙,也就是10ms
slowlog-max-len表示慢查询最大的条数,当slowlog超过设定的最大值后,会将最早的slowlog删除,是个FIFO队列
2.2 使用config方式动态设置slowlog
如下,可以通过config方式动态设置slowlog
1 2 3 4 5 6 7 8 9 10 |
|
3 slowlog 查看
3.1 查看slowlog总条数
1 2 |
|
3.2 查看slowlog
如果要获取指定的条数可以使用SLOWLOG GET N命令
1 2 3 4 5 6 |
|
slowlog源码解读
参考:http://blog.sina.com.cn/s/blog_48c95a190101gebh.html
写的很详细