1
votes

Redis forbids commands like 'EVAL' and 'EVALSHA' in user scripts. What can we benefit from scuh prohibition?

One way to bypass this limitation is to put all Lua scripts into one. However, it violate the scripts' maintainability. Is their any better solution?

1
You may want to consider lua-call: A wrapper and library to allow your Redis Lua scripts to call each other inside Redis.deltheil

1 Answers

0
votes

Redis forbids that because of replicatability in write operations.

The SHA1 checksum of the script should describe everything the Lua script does. When the script as well as the data is replicated, and executed on a Redis slave, the result should be exactly the same.

Therefore, functionality with a random nature, like rand or time are excluded from write operations. Why eval and evalsha are forbidden from read scripts as well, is probably because it makes the 'is-write-script' analysis impossible or at least cumbersome.

A possible solution on how to work around this, see this post.

We use this SHA1 response value loopback mechanism when connecting to different redis servers, see this diagram.

Hope this helps, TW