IO Costs of Redis Multi/Exec
I would like to send Redis a multi/exec command like the following:
redis 127.0.0.1:6379> MULTI OK redis 127.0.0.1:6379> LPUSH "JIMMY" "ABC" QUEUED redis 127.0.0.1:6379> LRANGE "JIMMY" 0 -1 QUEUED redis 127.0.0.1:6379> EXEC
However, I'd like to get an idea of the network I/O costs. It seems like there will be 4 trips and back and forwards, although I think Redis will keep the connection open?
Would it not be faster to send all of those commands in one block? Is it even possible to do that?
Yes, it is possible, and this is called pipelining. You don't have to wait for the server to answer before sending the next command unless you need results of the previous command to do this (i.e. there is a data dependency). You will receive server replies in-order afterwards. Commands in your example could be sent in a single TCP packet with the minimal possible overhead.
You can also use EVAL with a LUA script, commands are executed on the server:
eval "redis.call('lpush',KEYS,'abc'); return redis.call('lrange',KEYS,'0','-1');" 1 JIMMY