From e5ac39ac7b2728d14bfc27aac989b1085b7f6199 Mon Sep 17 00:00:00 2001 From: Jake Barnwell <2320567+jakebarnwell@users.noreply.github.com> Date: Tue, 22 Feb 2022 07:07:22 -0500 Subject: [PATCH] Add cluster support for scripting (#1937) * Add cluster support for scripting * Fall back to connection_pool.get_encoder if necessary * Add documentation for cluster-based scripting * Add test for flush response Co-authored-by: dvora-h --- README.md | 34 ++++++++++--- redis/cluster.py | 87 ++++++++++++++++++++++++++------- redis/commands/cluster.py | 9 +++- redis/commands/core.py | 56 +++++++++++++++++++++ redis/commands/parser.py | 17 ++++++- redis/utils.py | 2 +- tests/test_command_parser.py | 15 ++++++ tests/test_scripting.py | 94 +++++++++++++++++++++++++++++++++++- 8 files changed, 285 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index c6ee3c10eb..0735055820 100644 --- a/README.md +++ b/README.md @@ -862,7 +862,8 @@ Monitor object to block until a command is received. redis-py supports the EVAL, EVALSHA, and SCRIPT commands. However, there are a number of edge cases that make these commands tedious to use in real world scenarios. Therefore, redis-py exposes a Script object that -makes scripting much easier to use. +makes scripting much easier to use. (RedisClusters have limited support for +scripting.) To create a Script instance, use the register_script function on a client instance passing the Lua code as the first @@ -955,7 +956,7 @@ C 3 ### Cluster Mode -redis-py is now supports cluster mode and provides a client for +redis-py now supports cluster mode and provides a client for [Redis Cluster](). The cluster client is based on Grokzen's @@ -963,6 +964,8 @@ The cluster client is based on Grokzen's fixes, and now supersedes that library. Support for these changes is thanks to his contributions. +To learn more about Redis Cluster, see +[Redis Cluster specifications](https://redis.io/topics/cluster-spec). **Create RedisCluster:** @@ -1218,10 +1221,29 @@ according to their respective destination nodes. This means that we can not turn the pipeline commands into one transaction block, because in most cases they are split up into several smaller pipelines. - -See [Redis Cluster tutorial](https://redis.io/topics/cluster-tutorial) and -[Redis Cluster specifications](https://redis.io/topics/cluster-spec) -to learn more about Redis Cluster. +**Lua Scripting in Cluster Mode** + +Cluster mode has limited support for lua scripting. + +The following commands are supported, with caveats: +- `EVAL` and `EVALSHA`: The command is sent to the relevant node, depending on +the keys (i.e., in `EVAL "