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