Sled
Sled

Reputation: 18949

How to run a single Lua script against multiple Redis values in parallel?

In Redis we have strings that represent input values. We (would like to) have a Lua script that is dynamically generated (after being defined by user using a GUI) that calculates a result string based on the input string. Each set of input values is independent of each other. So this should be trivially parallelisable, however, EVAL seems to block until completion.

Is there a way in Redis to run a single Lua script across a bunch of values without having to rewrite the script itself to do it?

Upvotes: 0

Views: 906

Answers (1)

Elior Malul
Elior Malul

Reputation: 691

Since Redis is implemented as a single-threaded server, it would not be possible to run multiple commands from the same client in parallel. You should be however, be able to run multiple commands, (script commands included), on multiple clients, and Redis will interleave them in its IO loop.

Having said that, Redis is not only super-fast, it is also flexible; Please consider one of the following options:

  1. Write a Redis module yourself, add a command, or add a new command to your likings.
  2. Consider a multi-sharded environment. This will enable each redis-server (or shard) to run independently, while you can direct the call to the correct shard. This is somewhat labor-intensive, if you consider this solution, please let me know I can further instruct you on the matter.

All the best!

Upvotes: 2

Related Questions