Skip to content

Commit

Permalink
Allow EVAL_RO and EVALSHA_RO to be routed to read replica (#2494)
Browse files Browse the repository at this point in the history
* fix typo (Lue -> Lua)

* run eval_ro, evalsha_ro test on redis cluster

* Add eval_ro, evalsha_ro to read only commands

* assert that commands are run in a round robin manner

Co-authored-by: zach.lee <zach.lee@sendbird.com>
Co-authored-by: dvora-h <67596500+dvora-h@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 25, 2022
1 parent 55298e4 commit d693221
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions redis/commands/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
[
"BITCOUNT",
"BITPOS",
"EVAL_RO",
"EVALSHA_RO",
"EXISTS",
"GEODIST",
"GEOHASH",
Expand Down
2 changes: 1 addition & 1 deletion redis/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5139,7 +5139,7 @@ def eval_ro(
"""
The read-only variant of the EVAL command
Execute the read-only Lue ``script`` specifying the ``numkeys`` the script
Execute the read-only Lua ``script`` specifying the ``numkeys`` the script
will touch and the key names and argument values in ``keys_and_args``.
Returns the result of the script.
Expand Down
10 changes: 9 additions & 1 deletion tests/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,15 @@ def parse_response_mock_third(connection, *args, **options):
read_cluster.get("foo")
read_cluster.get("foo")
read_cluster.get("foo")
mocks["send_command"].assert_has_calls([call("READONLY")])
mocks["send_command"].assert_has_calls(
[
call("READONLY"),
call("GET", "foo"),
call("READONLY"),
call("GET", "foo"),
call("GET", "foo"),
]
)

def test_keyslot(self, r):
"""
Expand Down
2 changes: 0 additions & 2 deletions tests/test_scripting.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def test_eval_multiply(self, r):

@skip_if_server_version_lt("7.0.0")
@skip_if_redis_enterprise()
@pytest.mark.onlynoncluster
def test_eval_ro(self, r):
r.set("a", "b")
assert r.eval_ro("return redis.call('GET', KEYS[1])", 1, "a") == b"b"
Expand Down Expand Up @@ -157,7 +156,6 @@ def test_evalsha(self, r):

@skip_if_server_version_lt("7.0.0")
@skip_if_redis_enterprise()
@pytest.mark.onlynoncluster
def test_evalsha_ro(self, r):
r.set("a", "b")
get_sha = r.script_load("return redis.call('GET', KEYS[1])")
Expand Down

0 comments on commit d693221

Please sign in to comment.