summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordvora-h <67596500+dvora-h@users.noreply.github.com>2022-05-31 15:47:24 +0300
committerGitHub <noreply@github.com>2022-05-31 15:47:24 +0300
commit04bc576679e9fedb24a0548521d80fe81c91e2ec (patch)
tree6f1aec5c276393ac1917e372ac39858e9a48b3d5
parent4a73d85c78ce0ca36e5100b7ee0047b773cec23f (diff)
downloadredis-py-04bc576679e9fedb24a0548521d80fe81c91e2ec.tar.gz
Fix tests for Redis 7 (#2182)
* fix tests * async
-rw-r--r--redis/cluster.py1
-rw-r--r--redis/commands/parser.py2
-rw-r--r--tests/test_asyncio/test_commands.py36
-rw-r--r--tests/test_cluster.py37
-rw-r--r--tests/test_command_parser.py4
-rw-r--r--tests/test_commands.py30
-rw-r--r--tests/test_encoding.py2
-rw-r--r--tests/test_function.py51
-rw-r--r--tests/test_scripting.py4
9 files changed, 93 insertions, 74 deletions
diff --git a/redis/cluster.py b/redis/cluster.py
index 2e31063..a88792b 100644
--- a/redis/cluster.py
+++ b/redis/cluster.py
@@ -303,6 +303,7 @@ class AbstractRedisCluster:
"CLUSTER KEYSLOT",
"COMMAND",
"COMMAND COUNT",
+ "COMMAND LIST",
"COMMAND GETKEYS",
"CONFIG GET",
"DEBUG",
diff --git a/redis/commands/parser.py b/redis/commands/parser.py
index 7560603..115230a 100644
--- a/redis/commands/parser.py
+++ b/redis/commands/parser.py
@@ -79,7 +79,7 @@ class CommandsParser:
command = self.commands.get(cmd_name)
if "movablekeys" in command["flags"]:
keys = self._get_moveable_keys(redis_conn, *args)
- elif "pubsub" in command["flags"]:
+ elif "pubsub" in command["flags"] or command["name"] == "pubsub":
keys = self._get_pubsub_keys(*args)
else:
if (
diff --git a/tests/test_asyncio/test_commands.py b/tests/test_asyncio/test_commands.py
index 6fa702d..e128ac4 100644
--- a/tests/test_asyncio/test_commands.py
+++ b/tests/test_asyncio/test_commands.py
@@ -517,13 +517,10 @@ class TestRedisCommands:
assert reset_commands_processed < prior_commands_processed
async def test_config_set(self, r: redis.Redis):
- data = await r.config_get()
- rdbname = data["dbfilename"]
- try:
- assert await r.config_set("dbfilename", "redis_py_test.rdb")
- assert (await r.config_get())["dbfilename"] == "redis_py_test.rdb"
- finally:
- assert await r.config_set("dbfilename", rdbname)
+ await r.config_set("timeout", 70)
+ assert (await r.config_get())["timeout"] == "70"
+ assert await r.config_set("timeout", 0)
+ assert (await r.config_get())["timeout"] == "0"
@pytest.mark.onlynoncluster
async def test_dbsize(self, r: redis.Redis):
@@ -541,7 +538,8 @@ class TestRedisCommands:
await r.set("b", "bar")
info = await r.info()
assert isinstance(info, dict)
- assert info["db9"]["keys"] == 2
+ assert "arch_bits" in info.keys()
+ assert "redis_version" in info.keys()
@pytest.mark.onlynoncluster
async def test_lastsave(self, r: redis.Redis):
@@ -2180,6 +2178,7 @@ class TestRedisCommands:
)
@skip_if_server_version_lt("3.0.0")
+ @skip_if_server_version_gte("7.0.0")
@pytest.mark.onlynoncluster
async def test_readwrite(self, r: redis.Redis):
assert await r.readwrite()
@@ -2543,7 +2542,7 @@ class TestRedisCommands:
justid=True,
) == [message_id]
- @skip_if_server_version_lt("5.0.0")
+ @skip_if_server_version_lt("7.0.0")
async def test_xclaim_trimmed(self, r: redis.Redis):
# xclaim should not raise an exception if the item is not there
stream = "stream"
@@ -2564,9 +2563,8 @@ class TestRedisCommands:
# xclaim them from consumer2
# the item that is still in the stream should be returned
item = await r.xclaim(stream, group, "consumer2", 0, [sid1, sid2])
- assert len(item) == 2
- assert item[0] == (None, None)
- assert item[1][0] == sid2
+ assert len(item) == 1
+ assert item[0][0] == sid2
@skip_if_server_version_lt("5.0.0")
async def test_xdel(self, r: redis.Redis):
@@ -2583,7 +2581,7 @@ class TestRedisCommands:
assert await r.xdel(stream, m1) == 1
assert await r.xdel(stream, m2, m3) == 2
- @skip_if_server_version_lt("5.0.0")
+ @skip_if_server_version_lt("7.0.0")
async def test_xgroup_create(self, r: redis.Redis):
# tests xgroup_create and xinfo_groups
stream = "stream"
@@ -2600,11 +2598,13 @@ class TestRedisCommands:
"consumers": 0,
"pending": 0,
"last-delivered-id": b"0-0",
+ "entries-read": None,
+ "lag": 1,
}
]
assert await r.xinfo_groups(stream) == expected
- @skip_if_server_version_lt("5.0.0")
+ @skip_if_server_version_lt("7.0.0")
async def test_xgroup_create_mkstream(self, r: redis.Redis):
# tests xgroup_create and xinfo_groups
stream = "stream"
@@ -2624,6 +2624,8 @@ class TestRedisCommands:
"consumers": 0,
"pending": 0,
"last-delivered-id": b"0-0",
+ "entries-read": None,
+ "lag": 0,
}
]
assert await r.xinfo_groups(stream) == expected
@@ -2658,7 +2660,7 @@ class TestRedisCommands:
await r.xgroup_create(stream, group, 0)
assert await r.xgroup_destroy(stream, group)
- @skip_if_server_version_lt("5.0.0")
+ @skip_if_server_version_lt("7.0.0")
async def test_xgroup_setid(self, r: redis.Redis):
stream = "stream"
group = "group"
@@ -2666,13 +2668,15 @@ class TestRedisCommands:
await r.xgroup_create(stream, group, 0)
# advance the last_delivered_id to the message_id
- await r.xgroup_setid(stream, group, message_id)
+ await r.xgroup_setid(stream, group, message_id, entries_read=2)
expected = [
{
"name": group.encode(),
"consumers": 0,
"pending": 0,
"last-delivered-id": message_id,
+ "entries-read": 2,
+ "lag": -1,
}
]
assert await r.xinfo_groups(stream) == expected
diff --git a/tests/test_cluster.py b/tests/test_cluster.py
index c74af20..d1568ef 100644
--- a/tests/test_cluster.py
+++ b/tests/test_cluster.py
@@ -858,15 +858,15 @@ class TestClusterRedisCommands:
assert isinstance(cluster_shards, list)
assert isinstance(cluster_shards[0], dict)
attributes = [
- "id",
- "endpoint",
- "ip",
- "hostname",
- "port",
- "tls-port",
- "role",
- "replication-offset",
- "health",
+ b"id",
+ b"endpoint",
+ b"ip",
+ b"hostname",
+ b"port",
+ b"tls-port",
+ b"role",
+ b"replication-offset",
+ b"health",
]
for x in cluster_shards:
assert list(x.keys()) == ["slots", "nodes"]
@@ -915,9 +915,24 @@ class TestClusterRedisCommands:
@skip_if_server_version_lt("7.0.0")
@skip_if_redis_enterprise()
- def test_cluster_delslotsrange(self, r):
+ def test_cluster_delslotsrange(self):
+ cluster_slots = [
+ [
+ 0,
+ 8191,
+ ["127.0.0.1", 7000, "node_0"],
+ ],
+ [
+ 8192,
+ 16383,
+ ["127.0.0.1", 7001, "node_1"],
+ ],
+ ]
+ r = get_mocked_redis_client(
+ host=default_host, port=default_port, cluster_slots=cluster_slots
+ )
+ mock_all_nodes_resp(r, "OK")
node = r.get_random_node()
- mock_node_resp(node, "OK")
r.cluster_addslots(node, 1, 2, 3, 4, 5)
assert r.cluster_delslotsrange(1, 5)
diff --git a/tests/test_command_parser.py b/tests/test_command_parser.py
index 134909f..708c069 100644
--- a/tests/test_command_parser.py
+++ b/tests/test_command_parser.py
@@ -50,8 +50,6 @@ class TestCommandsParser:
"key3",
]
args7 = ["MIGRATE", "192.168.1.34", 6379, "key1", 0, 5000]
- args8 = ["STRALGO", "LCS", "STRINGS", "string_a", "string_b"]
- args9 = ["STRALGO", "LCS", "KEYS", "key1", "key2"]
assert commands_parser.get_keys(r, *args1).sort() == ["key1", "key2"].sort()
assert (
@@ -68,8 +66,6 @@ class TestCommandsParser:
== ["key1", "key2", "key3"].sort()
)
assert commands_parser.get_keys(r, *args7).sort() == ["key1"].sort()
- assert commands_parser.get_keys(r, *args8) is None
- assert commands_parser.get_keys(r, *args9).sort() == ["key1", "key2"].sort()
# A bug in redis<7.0 causes this to fail: https://github.com/redis/redis/issues/9493
@skip_if_server_version_lt("7.0.0")
diff --git a/tests/test_commands.py b/tests/test_commands.py
index d4a564c..1ae6219 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -670,7 +670,7 @@ class TestRedisCommands:
@pytest.mark.onlynoncluster
@skip_if_server_version_lt("7.0.0")
def test_client_no_evict(self, r):
- assert r.client_no_evict("ON") == "OK"
+ assert r.client_no_evict("ON")
with pytest.raises(TypeError):
r.client_no_evict()
@@ -1089,9 +1089,9 @@ class TestRedisCommands:
@skip_if_server_version_lt("7.0.0")
def test_lcs(self, r):
r.mset({"foo": "ohmytext", "bar": "mynewtext"})
- assert r.lcs("foo", "bar") == "mytext"
+ assert r.lcs("foo", "bar") == b"mytext"
assert r.lcs("foo", "bar", len=True) == 6
- result = ["matches", [[[4, 7], [5, 8]]], "len", 6]
+ result = [b"matches", [[[4, 7], [5, 8]]], b"len", 6]
assert r.lcs("foo", "bar", idx=True, minmatchlen=3) == result
with pytest.raises(redis.ResponseError):
assert r.lcs("foo", "bar", len=True, idx=True)
@@ -1764,24 +1764,24 @@ class TestRedisCommands:
@skip_if_server_version_lt("7.0.0")
def test_blmpop(self, r):
r.rpush("a", "1", "2", "3", "4", "5")
- res = ["a", ["1", "2"]]
+ res = [b"a", [b"1", b"2"]]
assert r.blmpop(1, "2", "b", "a", direction="LEFT", count=2) == res
with pytest.raises(TypeError):
r.blmpop(1, "2", "b", "a", count=2)
r.rpush("b", "6", "7", "8", "9")
- assert r.blmpop(0, "2", "b", "a", direction="LEFT") == ["b", ["6"]]
+ assert r.blmpop(0, "2", "b", "a", direction="LEFT") == [b"b", [b"6"]]
assert r.blmpop(1, "2", "foo", "bar", direction="RIGHT") is None
@pytest.mark.onlynoncluster
@skip_if_server_version_lt("7.0.0")
def test_lmpop(self, r):
r.rpush("foo", "1", "2", "3", "4", "5")
- result = ["foo", ["1", "2"]]
+ result = [b"foo", [b"1", b"2"]]
assert r.lmpop("2", "bar", "foo", direction="LEFT", count=2) == result
with pytest.raises(redis.ResponseError):
r.lmpop("2", "bar", "foo", direction="up", count=2)
r.rpush("bar", "a", "b", "c", "d")
- assert r.lmpop("2", "bar", "foo", direction="LEFT") == ["bar", ["a"]]
+ assert r.lmpop("2", "bar", "foo", direction="LEFT") == [b"bar", [b"a"]]
def test_lindex(self, r):
r.rpush("a", "1", "2", "3")
@@ -2393,23 +2393,23 @@ class TestRedisCommands:
@skip_if_server_version_lt("7.0.0")
def test_zmpop(self, r):
r.zadd("a", {"a1": 1, "a2": 2, "a3": 3})
- res = ["a", [["a1", "1"], ["a2", "2"]]]
+ res = [b"a", [[b"a1", b"1"], [b"a2", b"2"]]]
assert r.zmpop("2", ["b", "a"], min=True, count=2) == res
with pytest.raises(redis.DataError):
r.zmpop("2", ["b", "a"], count=2)
r.zadd("b", {"b1": 10, "ab": 9, "b3": 8})
- assert r.zmpop("2", ["b", "a"], max=True) == ["b", [["b1", "10"]]]
+ assert r.zmpop("2", ["b", "a"], max=True) == [b"b", [[b"b1", b"10"]]]
@pytest.mark.onlynoncluster
@skip_if_server_version_lt("7.0.0")
def test_bzmpop(self, r):
r.zadd("a", {"a1": 1, "a2": 2, "a3": 3})
- res = ["a", [["a1", "1"], ["a2", "2"]]]
+ res = [b"a", [[b"a1", b"1"], [b"a2", b"2"]]]
assert r.bzmpop(1, "2", ["b", "a"], min=True, count=2) == res
with pytest.raises(redis.DataError):
r.bzmpop(1, "2", ["b", "a"], count=2)
r.zadd("b", {"b1": 10, "ab": 9, "b3": 8})
- res = ["b", [["b1", "10"]]]
+ res = [b"b", [[b"b1", b"10"]]]
assert r.bzmpop(0, "2", ["b", "a"], max=True) == res
assert r.bzmpop(1, "2", ["foo", "bar"], max=True) is None
@@ -3100,6 +3100,7 @@ class TestRedisCommands:
@pytest.mark.onlynoncluster
@skip_if_server_version_lt("3.0.0")
+ @skip_if_server_version_gte("7.0.0")
@skip_if_redis_enterprise()
def test_readwrite(self, r):
assert r.readwrite()
@@ -4510,7 +4511,7 @@ class TestRedisCommands:
assert len(r.command_list()) > 300
assert len(r.command_list(module="fakemod")) == 0
assert len(r.command_list(category="list")) > 15
- assert "lpop" in r.command_list(pattern="l*")
+ assert b"lpop" in r.command_list(pattern="l*")
with pytest.raises(redis.ResponseError):
r.command_list(category="list", pattern="l*")
@@ -4546,7 +4547,10 @@ class TestRedisCommands:
@skip_if_server_version_lt("7.0.0")
@skip_if_redis_enterprise()
def test_command_getkeysandflags(self, r: redis.Redis):
- res = [["mylist1", ["RW", "access", "delete"]], ["mylist2", ["RW", "insert"]]]
+ res = [
+ [b"mylist1", [b"RW", b"access", b"delete"]],
+ [b"mylist2", [b"RW", b"insert"]],
+ ]
assert res == r.command_getkeysandflags(
"LMOVE", "mylist1", "mylist2", "left", "left"
)
diff --git a/tests/test_encoding.py b/tests/test_encoding.py
index d7d1fb1..2867640 100644
--- a/tests/test_encoding.py
+++ b/tests/test_encoding.py
@@ -90,7 +90,7 @@ class TestMemoryviewsAreNotPacked:
class TestCommandsAreNotEncoded:
@pytest.fixture()
def r(self, request):
- return _get_client(redis.Redis, request=request, encoding="utf-16")
+ return _get_client(redis.Redis, request=request, encoding="utf-8")
def test_basic_command(self, r):
r.set("hello", "world")
diff --git a/tests/test_function.py b/tests/test_function.py
index 70f6b19..7ce66a3 100644
--- a/tests/test_function.py
+++ b/tests/test_function.py
@@ -22,10 +22,10 @@ class TestFunction:
def reset_functions(self, r):
r.function_flush()
+ @pytest.mark.onlynoncluster
def test_function_load(self, r):
- print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
- assert lib == r.function_load(f"#!{engine} name={lib} \n {function}")
- assert lib == r.function_load(
+ assert b"mylib" == r.function_load(f"#!{engine} name={lib} \n {function}")
+ assert b"mylib" == r.function_load(
f"#!{engine} name={lib} \n {function}", replace=True
)
with pytest.raises(ResponseError):
@@ -37,15 +37,14 @@ class TestFunction:
r.function_load(f"#!{engine} name={lib} \n {set_function}")
with pytest.raises(ResponseError):
r.function_load(f"#!{engine} name={lib} \n {set_function}")
- assert r.fcall("set", 1, "foo", "bar") == "OK"
+ assert r.fcall("set", 1, "foo", "bar") == b"OK"
assert r.function_delete("mylib")
with pytest.raises(ResponseError):
r.fcall("set", 1, "foo", "bar")
- assert lib == r.function_load(f"#!{engine} name={lib} \n {set_function}")
def test_function_flush(self, r):
r.function_load(f"#!{engine} name={lib} \n {function}")
- assert r.fcall("myfunc", 0, "hello") == "hello"
+ assert r.fcall("myfunc", 0, "hello") == b"hello"
assert r.function_flush()
with pytest.raises(ResponseError):
r.fcall("myfunc", 0, "hello")
@@ -57,19 +56,19 @@ class TestFunction:
r.function_load(f"#!{engine} name={lib} \n {function}")
res = [
[
- "library_name",
- "mylib",
- "engine",
- "LUA",
- "functions",
- [["name", "myfunc", "description", None, "flags", ["no-writes"]]],
+ b"library_name",
+ b"mylib",
+ b"engine",
+ b"LUA",
+ b"functions",
+ [[b"name", b"myfunc", b"description", None, b"flags", [b"no-writes"]]],
]
]
assert r.function_list() == res
assert r.function_list(library="*lib") == res
assert (
r.function_list(withcode=True)[0][7]
- == f"#!{engine} name={lib} \n {function}"
+ == f"#!{engine} name={lib} \n {function}".encode()
)
@pytest.mark.onlycluster
@@ -77,12 +76,12 @@ class TestFunction:
r.function_load(f"#!{engine} name={lib} \n {function}")
function_list = [
[
- "library_name",
- "mylib",
- "engine",
- "LUA",
- "functions",
- [["name", "myfunc", "description", None, "flags", ["no-writes"]]],
+ b"library_name",
+ b"mylib",
+ b"engine",
+ b"LUA",
+ b"functions",
+ [[b"name", b"myfunc", b"description", None, b"flags", [b"no-writes"]]],
]
]
primaries = r.get_primaries()
@@ -94,20 +93,20 @@ class TestFunction:
node = primaries[0].name
assert (
r.function_list(withcode=True)[node][0][7]
- == f"#!{engine} name={lib} \n {function}"
+ == f"#!{engine} name={lib} \n {function}".encode()
)
def test_fcall(self, r):
r.function_load(f"#!{engine} name={lib} \n {set_function}")
r.function_load(f"#!{engine} name={lib2} \n {get_function}")
- assert r.fcall("set", 1, "foo", "bar") == "OK"
- assert r.fcall("get", 1, "foo") == "bar"
+ assert r.fcall("set", 1, "foo", "bar") == b"OK"
+ assert r.fcall("get", 1, "foo") == b"bar"
with pytest.raises(ResponseError):
r.fcall("myfunc", 0, "hello")
def test_fcall_ro(self, r):
r.function_load(f"#!{engine} name={lib} \n {function}")
- assert r.fcall_ro("myfunc", 0, "hello") == "hello"
+ assert r.fcall_ro("myfunc", 0, "hello") == b"hello"
r.function_load(f"#!{engine} name={lib2} \n {set_function}")
with pytest.raises(ResponseError):
r.fcall_ro("set", 1, "foo", "bar")
@@ -115,14 +114,14 @@ class TestFunction:
def test_function_dump_restore(self, r):
r.function_load(f"#!{engine} name={lib} \n {set_function}")
payload = r.function_dump()
- assert r.fcall("set", 1, "foo", "bar") == "OK"
+ assert r.fcall("set", 1, "foo", "bar") == b"OK"
r.function_delete("mylib")
with pytest.raises(ResponseError):
r.fcall("set", 1, "foo", "bar")
assert r.function_restore(payload)
- assert r.fcall("set", 1, "foo", "bar") == "OK"
+ assert r.fcall("set", 1, "foo", "bar") == b"OK"
r.function_load(f"#!{engine} name={lib2} \n {get_function}")
- assert r.fcall("get", 1, "foo") == "bar"
+ assert r.fcall("get", 1, "foo") == b"bar"
r.function_delete("mylib")
assert r.function_restore(payload, "FLUSH")
with pytest.raises(ResponseError):
diff --git a/tests/test_scripting.py b/tests/test_scripting.py
index 1ccd99a..bbe845c 100644
--- a/tests/test_scripting.py
+++ b/tests/test_scripting.py
@@ -70,7 +70,7 @@ class TestScripting:
@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"
+ assert r.eval_ro("return redis.call('GET', KEYS[1])", 1, "a") == b"b"
with pytest.raises(redis.ResponseError):
r.eval_ro("return redis.call('DEL', KEYS[1])", 1, "a")
@@ -162,7 +162,7 @@ class TestScripting:
r.set("a", "b")
get_sha = r.script_load("return redis.call('GET', KEYS[1])")
del_sha = r.script_load("return redis.call('DEL', KEYS[1])")
- assert r.evalsha_ro(get_sha, 1, "a") == "b"
+ assert r.evalsha_ro(get_sha, 1, "a") == b"b"
with pytest.raises(redis.ResponseError):
r.evalsha_ro(del_sha, 1, "a")