LUA - How to predeclare keys when key is calculated inside LUA script?

55 views
Skip to first unread message

Victor Efimov

unread,
May 3, 2018, 11:18:23 AM5/3/18
to Redis DB
From the docs:


====
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.

===


But what to do when LUA code reads value of key "X", and then use it to construct name of another key to access?

I understand there is no way to correctly "declare" all keys for such LUA code. Will this code work well (except Redis cluster), or it's kind of bad practice etc?

Itamar Haber

unread,
May 4, 2018, 10:34:33 AM5/4/18
to Redis DB
Hello Victor,

Your understanding is correct, there is no "right" way to do that.

Currently, if you're using Redis in single-instance mode, there are no known side effects. However.

As you've mentioned, this approach breaks in the cluster, so it seriously limits your scalability. Even if you're not using the cluster, but using a 3rd party proxy, this will cause problems.

Cheers,

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+unsubscribe@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.



--

Itamar Haber | Technology Evangelist
Redis Labs ~/redis

Mobile: +972 (54) 567 9692
Twitter: @itamarhaber
Skype: itamar.haber

Victor Efimov

unread,
May 4, 2018, 12:07:20 PM5/4/18
to Redis DB
Thank you very much!


On Friday, May 4, 2018 at 5:34:33 PM UTC+3, Itamar Haber wrote:
Hello Victor,

Your understanding is correct, there is no "right" way to do that.

Currently, if you're using Redis in single-instance mode, there are no known side effects. However.

As you've mentioned, this approach breaks in the cluster, so it seriously limits your scalability. Even if you're not using the cluster, but using a 3rd party proxy, this will cause problems.

Cheers,
On Thu, May 3, 2018 at 6:18 PM, Victor Efimov <vic...@vsespb.ru> wrote:
From the docs:


====
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.

===


But what to do when LUA code reads value of key "X", and then use it to construct name of another key to access?

I understand there is no way to correctly "declare" all keys for such LUA code. Will this code work well (except Redis cluster), or it's kind of bad practice etc?

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.

To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages