1
votes

env: Redis Cluster

Hi. My requirement is:

Find value-B thought key-A (The process is use key-A find out value-A, the value-A == key-B, use key-B find out value-B )

my lua looks like this:

[root@ml-208 redis]# cat x-userid-tag.lua

local f3=redis.call('HGET',KEYS[1],'1'); local f4=redis.call('HGET',f3,'1') ; return f4;

my redis cmd:

./bin/redis-cli -c -h 192.168.33.203 -p 6000 --eval ./x-userid-tag.lua 0C559F3FEF368A8B53DE69C267423F0E

error msg: (error) ERR Error running script (call to f_9bd20ba85f7bcc8ee1f6b55c4158bfa93eba2221): @user_script:2: @user_script: 2: Lua script attempted to access a non local key in a cluster node

1

1 Answers

2
votes

Lua script runs on only one redis instance and its internal queries are not redirected by the cluster, So, it cannot query two keys if they are present in another cluster.

In your case, keyA and valueA(which is keyB) are hashed to different slots and to different nodes, so the lua will not work.

One way to fix it is to have the following as keys and value.

If you have a 'key1', and its value as 'value1', instead of keeping its value/key2 as 'value1', you should keep it as '{key1}:value1'. Redis will make sure that both 'key1' and '{key1}:value1' are hashed to a single node, and you will be able to query both of them using lua.