redisspring-data-redislettuce

Have read-only Lua script executed against read replicas in a Redis cluster


I have:

  1. A Redis cluster with primary nodes and read replicas.
  2. Lua scripts that write data (keys).
  3. Lua scripts that only read data.

I want to have the read-only Lua scripts executed against replicas in my Redis cluster. How can I do that?

Best as I can tell, the ReadFrom.REPLICA_PREFERRED option only works for read commands, i.e. GET or SCAN.

I am using the Spring Data Redis library.


Solution

  • You can use Eval flags:

    Normally, when you run an Eval script, the server does not know how it accesses the database. By default, Redis assumes that all scripts read and write data. However, starting with Redis 7.0, there's a way to declare flags when creating a script in order to tell Redis how it should behave.

    with the flag no-writes: this flag indicates that the script only reads data but never writes.

    #!lua flags=no-writes
    

    More information about Read-only scripts.