redis - Redis-Cli 中的定时查询?

标签 redis

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

最佳答案

您可以通过将正在研究的 redis 命令包装在 MULTI/EXEC 中来完成此操作 block ,其中 TIME命令在您的命令之前之后使用。例如:

使用节点库:

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
});

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

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 微秒。

关于redis - Redis-Cli 中的定时查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18134167/

相关文章:

php - 命令执行期间如何禁用Redis日志

asp.net - 实际上,删除 session 状态请求锁是否会实际影响站点

mysql - redis能否完全替代mysql?

data-structures - 为什么 Redis SortedSet 使用 Skip List 而不是 Balanced Tree?

单个哈希键的 Redis 最大值大小

redis - Spring XD分布式模式redis配置

performance - 如何识别 Redis 性能/瓶颈

python - 在 asyncio 事件循环中运行协程和线程 : Errors while exiting

Redis 增加一个数值 - ERR 值不是整数或超出范围

c# - Microsoft ASP.NET Redis session 状态引发异常