zio-redis icon indicating copy to clipboard operation
zio-redis copied to clipboard

Support Cross-slot command execution in Cluster

Open anatolysergeev opened this issue 2 years ago • 0 comments

We can add support for some commands like it's been done in lettuce

Regular Redis Cluster commands are limited to single-slot keys operation – either single key commands or multi-key commands that share the same hash slot.

  • [x] Commands without a key are executed on the default connection that points most likely to the first provided RedisURI. The same rule applies to commands operating on multiple keys but with the limitation that all keys have to be in the same slot.

The cross slot limitation can be mitigated by using the advanced cluster API for a set of selected multi-key commands. Commands that operate on keys with different slots are decomposed into multiple commands. The single commands are fired in a fork/join fashion. The commands are issued concurrently to avoid synchronous chaining. Results are synchronized before the command is completed.

Following commands can be supported for cross-slot command execution:

  • [ ] DEL: Delete the KEYs. Returns the number of keys that were removed.
  • [ ] EXISTS: Count the number of KEYs that exist across the master nodes being responsible for the particular key.
  • [ ] MGET: Get the values of all given KEYs. Returns the values in the order of the keys.
  • [ ] MSET: Set multiple key/value pairs for all given KEYs. Returns always OK.
  • [ ] TOUCH: Alters the last access time of all given KEYs. Returns the number of keys that were touched.
  • [ ] UNLINK: Delete the KEYs and reclaiming memory in a different thread. Returns the number of keys that were removed.

Following commands can be executed on multiple cluster nodes operations:

  • [ ] CLIENT SETNAME: Set the client name on all known cluster node connections. Returns always OK.
  • [ ] KEYS: Return/Stream all keys that are stored on all masters.
  • [ ] DBSIZE: Return the number of keys that are stored on all masters.
  • [ ] FLUSHALL: Flush all data on the cluster masters. Returns always OK.
  • [ ] FLUSHDB: Flush all data on the cluster masters. Returns always OK.
  • [ ] RANDOMKEY: Return a random key from a random master.
  • [ ] SCAN: Scan the keyspace across the whole cluster according to ReadFrom settings.
  • [ ] SCRIPT FLUSH: Remove all the scripts from the script cache on all cluster nodes.
  • [ ] SCRIPT LOAD: Load the script into the Lua script cache on all nodes.
  • [ ] SCRIPT KILL: Kill the script currently in execution on all cluster nodes. This call does not fail even if no scripts are running.
  • [ ] SHUTDOWN: Synchronously save the dataset to disk and then shut down all nodes of the cluster.

anatolysergeev avatar Nov 12 '22 19:11 anatolysergeev