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?
The TIME command returns the current server time as a two items lists: a Unix timestamp and the amount of microseconds already elapsed in the current second.
The maximum length of time to wait while establishing a connection to a Redis server.
The Redis command line interface ( redis-cli ) is a terminal program used to send commands to and read replies from the Redis server.
To start Redis client, open the terminal and type the command redis-cli. This will connect to your local server and now you can run any command. In the above example, we connect to Redis server running on the local machine and execute a command PING, that checks whether the server is running or not.
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:
Using the node library:
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"
And then do the math yourself. The above example took 3 microseconds.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With