Redis-Cli 中的计时查询? [英] Timing Queries in Redis-Cli?

查看:59
本文介绍了Redis-Cli 中的计时查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这看起来应该是微不足道的,但我想通过 redis-cli 运行查询,然后返回在服务器上花费的时间以及结果.这仅用于调试目的,以解决我的客户端库或延迟问题.有没有办法做到这一点?

This seems like it ought to be trivial, but I want to run a query through redis-cli, and then just get back how long it took on the server, along with the results. This is just for debugging purposes, to factor out problems with my client library or latency. Is there a way to do this?

推荐答案

您可以通过将您正在研究的 redis 命令包装在 MULTI/EXEC 块中来实现,其中 TIME 命令在您的命令的右侧 before 和右侧 after 使用.例如:

You can do this by wrapping the redis command you're investigating in a MULTI/EXEC block, where the TIME command is used right before and right after your command. For example:

使用节点库:

var multi = redis.multi();
multi.time(); // start time
multi.sunionstore(['fast_food_joints', 'pizza_hut', 'taco_bell']); // this is the command I'm investigating
multi.time(); // end time
multi.exec(function(err, responses){
    var response = responses[1]; // the response i care about
    var start = (parseInt(responses[0][0]) * 1000) + (parseInt(responses[0][1]) / 1000);
    var end   = (parseInt(responses[2][0]) * 1000) + (parseInt(responses[2][1]) / 1000);            
    var execution_time = end - start; // in milliseconds
});

或者...使用命令行(这是您在问题中要求的):

Or... using the command line (which is what you asked for in your question):

192.168.1.1:6379> MULTI
OK
192.168.1.1:6379> TIME
QUEUED
192.168.1.1:6379> SUNIONSTORE fast_food_joints pizza_hut taco_bell
QUEUED
192.168.1.1:6379> TIME
QUEUED
192.168.1.1:6379> EXEC
1) 1) "1450818240"
   2) "666636"
2) (integer) 48886
3) 1) "1450818240"
   2) "666639"

然后自己算一下.上面的例子用了 3 微秒.

And then do the math yourself. The above example took 3 microseconds.

这篇关于Redis-Cli 中的计时查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆