Why can't my Redis Lua script atomically update keys on different Redis Cluster nodes?
<p>I have a Redis Cluster consisting of multiple nodes. I want to update 3 different keys in a single atomic operation. My Lua script is like:</p>
<pre><code>local u1 = redis.call('incrby', KEYS[1], ARGV[1])
local u2 = redis.call('incrby', KEYS[2], ARGV[1])
local u3 = redis.call('incrby', KEYS[3], ARGV[1])
</code></pre>
<p>And I fired it with:</p>
<pre><code>EVAL script 3 key1 key2 key3 arg
</code></pre>
<p>But I got the error message:</p>
<pre><code>WARN Resp(AppErr CROSSSLOT Keys in request don't hash to the same slot)
</code></pre>
<p>The above operations cannot be done, and the updates will fail.  It seems I cannot modify the keys in different nodes with a single Lua script.  But according to the doc:</p>
<blockquote>
<p>All Redis commands must be analyzed before execution to determine
which keys the command will operate on. In order for this to be true
for EVAL, keys must be passed explicitly. This is useful in many ways,
but especially to make sure Redis Cluster can forward your request to
the appropriate cluster node.</p>
<p>Note 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.</p>
</blockquote>
<p>So I think as long as I follow the key passing rule, the script should be compatible with Redis Cluster. I wonder what's the problem here and what should I do to update all keys in a single script.</p>