1
votes

Here is an example scenario to illustrate:

Suppose we have some key=>value pairs:

hmset thing1 name 'a thing' color red
hmset thing2 name 'another thing' color green
hmset thing3 name 'also a thing' color blue

And a list whose values are key names:

lpush things thing1
lpush things thing2
lpush things thing3

My goal is to use indirection to get values from a range of things:

thingsArray = lrange things 0 2
for each thing in thingsArray
  result.push(hmget thing name color)

But the penalty for this is extra round trips. I realize this can be mitigated to some extent with pipelining, but was hoping it is possible with just one round trip with a Lua script. So something like:

eval superAwesomeScript 1 things 0 2

The problem is, I wouldn't know which keys will be returned by the lrange call on the "things" list at the time I am calling the Lua script. Does accessing the data in this way in a Lua script violate the rules suggested for future-proofing for Redis Cluster?

I am fairly new to Redis and a total noob with Lua, so if I am way off base in my goals, please tell me so. Also, my main concern with multiple round trips is network io, particularly within a horizontally scaled cluster. So, entirely different solutions would be welcome as well.

1

1 Answers

2
votes

From EVAL docs:

The reason for passing keys in the proper way is that, before EVAL all the Redis commands could be analyzed before execution in order to establish what keys the command will operate on.

In order for this to be true for EVAL also keys must be explicit. This is useful in many ways, but especially in order to make sure Redis Cluster is able to forward your request to the appropriate cluster node (Redis Cluster is a work in progress, but the scripting feature was designed in order to play well with it). However this rule is not enforced in order to provide the user with opportunities to abuse the Redis single instance configuration, at the cost of writing scripts not compatible with Redis Cluster.