Skip to content

Commit

Permalink
Add modules support to async RedisCluster (#3115)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvora-h committed Feb 25, 2024
1 parent 4528726 commit 8e5020e
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 112 deletions.
3 changes: 2 additions & 1 deletion redis/commands/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
ScriptCommands,
)
from .helpers import list_or_args
from .redismodules import RedisModuleCommands
from .redismodules import AsyncRedisModuleCommands, RedisModuleCommands

if TYPE_CHECKING:
from redis.asyncio.cluster import TargetNodesT
Expand Down Expand Up @@ -907,6 +907,7 @@ class AsyncRedisClusterCommands(
AsyncFunctionCommands,
AsyncGearsCommands,
AsyncModuleCommands,
AsyncRedisModuleCommands,
):
"""
A class for all Redis Cluster commands
Expand Down
26 changes: 1 addition & 25 deletions tests/test_asyncio/test_bloom.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def intlist(obj):
return [int(v) for v in obj]


@pytest.mark.redismod
async def test_create(decoded_r: redis.Redis):
"""Test CREATE/RESERVE calls"""
assert await decoded_r.bf().create("bloom", 0.01, 1000)
Expand All @@ -30,13 +29,11 @@ async def test_create(decoded_r: redis.Redis):
assert await decoded_r.topk().reserve("topk", 5, 100, 5, 0.9)


@pytest.mark.redismod
@pytest.mark.experimental
async def test_tdigest_create(decoded_r: redis.Redis):
assert await decoded_r.tdigest().create("tDigest", 100)


@pytest.mark.redismod
async def test_bf_add(decoded_r: redis.Redis):
assert await decoded_r.bf().create("bloom", 0.01, 1000)
assert 1 == await decoded_r.bf().add("bloom", "foo")
Expand All @@ -49,7 +46,6 @@ async def test_bf_add(decoded_r: redis.Redis):
assert [1, 0] == intlist(await decoded_r.bf().mexists("bloom", "foo", "noexist"))


@pytest.mark.redismod
async def test_bf_insert(decoded_r: redis.Redis):
assert await decoded_r.bf().create("bloom", 0.01, 1000)
assert [1] == intlist(await decoded_r.bf().insert("bloom", ["foo"]))
Expand Down Expand Up @@ -80,7 +76,6 @@ async def test_bf_insert(decoded_r: redis.Redis):
)


@pytest.mark.redismod
async def test_bf_scandump_and_loadchunk(decoded_r: redis.Redis):
# Store a filter
await decoded_r.bf().create("myBloom", "0.0001", "1000")
Expand Down Expand Up @@ -132,7 +127,6 @@ async def do_verify():
await decoded_r.bf().create("myBloom", "0.0001", "10000000")


@pytest.mark.redismod
async def test_bf_info(decoded_r: redis.Redis):
expansion = 4
# Store a filter
Expand Down Expand Up @@ -164,7 +158,6 @@ async def test_bf_info(decoded_r: redis.Redis):
assert True


@pytest.mark.redismod
async def test_bf_card(decoded_r: redis.Redis):
# return 0 if the key does not exist
assert await decoded_r.bf().card("not_exist") == 0
Expand All @@ -179,7 +172,6 @@ async def test_bf_card(decoded_r: redis.Redis):
await decoded_r.bf().card("setKey")


@pytest.mark.redismod
async def test_cf_add_and_insert(decoded_r: redis.Redis):
assert await decoded_r.cf().create("cuckoo", 1000)
assert await decoded_r.cf().add("cuckoo", "filter")
Expand All @@ -205,7 +197,6 @@ async def test_cf_add_and_insert(decoded_r: redis.Redis):
)


@pytest.mark.redismod
async def test_cf_exists_and_del(decoded_r: redis.Redis):
assert await decoded_r.cf().create("cuckoo", 1000)
assert await decoded_r.cf().add("cuckoo", "filter")
Expand All @@ -217,7 +208,6 @@ async def test_cf_exists_and_del(decoded_r: redis.Redis):
assert 0 == await decoded_r.cf().count("cuckoo", "filter")


@pytest.mark.redismod
async def test_cms(decoded_r: redis.Redis):
assert await decoded_r.cms().initbydim("dim", 1000, 5)
assert await decoded_r.cms().initbyprob("prob", 0.01, 0.01)
Expand All @@ -233,7 +223,6 @@ async def test_cms(decoded_r: redis.Redis):
assert 25 == info["count"]


@pytest.mark.redismod
@pytest.mark.onlynoncluster
async def test_cms_merge(decoded_r: redis.Redis):
assert await decoded_r.cms().initbydim("A", 1000, 5)
Expand All @@ -251,7 +240,6 @@ async def test_cms_merge(decoded_r: redis.Redis):
assert [16, 15, 21] == await decoded_r.cms().query("C", "foo", "bar", "baz")


@pytest.mark.redismod
async def test_topk(decoded_r: redis.Redis):
# test list with empty buckets
assert await decoded_r.topk().reserve("topk", 3, 50, 4, 0.9)
Expand Down Expand Up @@ -332,7 +320,6 @@ async def test_topk(decoded_r: redis.Redis):
assert 0.9 == round(float(info["decay"]), 1)


@pytest.mark.redismod
async def test_topk_incrby(decoded_r: redis.Redis):
await decoded_r.flushdb()
assert await decoded_r.topk().reserve("topk", 3, 10, 3, 1)
Expand All @@ -347,7 +334,6 @@ async def test_topk_incrby(decoded_r: redis.Redis):
)


@pytest.mark.redismod
@pytest.mark.experimental
async def test_tdigest_reset(decoded_r: redis.Redis):
assert await decoded_r.tdigest().create("tDigest", 10)
Expand All @@ -364,7 +350,6 @@ async def test_tdigest_reset(decoded_r: redis.Redis):
)


@pytest.mark.redismod
@pytest.mark.onlynoncluster
async def test_tdigest_merge(decoded_r: redis.Redis):
assert await decoded_r.tdigest().create("to-tDigest", 10)
Expand Down Expand Up @@ -392,7 +377,6 @@ async def test_tdigest_merge(decoded_r: redis.Redis):
assert 4.0 == await decoded_r.tdigest().max("to-tDigest")


@pytest.mark.redismod
@pytest.mark.experimental
async def test_tdigest_min_and_max(decoded_r: redis.Redis):
assert await decoded_r.tdigest().create("tDigest", 100)
Expand All @@ -403,7 +387,6 @@ async def test_tdigest_min_and_max(decoded_r: redis.Redis):
assert 1 == await decoded_r.tdigest().min("tDigest")


@pytest.mark.redismod
@pytest.mark.experimental
@skip_ifmodversion_lt("2.4.0", "bf")
async def test_tdigest_quantile(decoded_r: redis.Redis):
Expand Down Expand Up @@ -432,7 +415,6 @@ async def test_tdigest_quantile(decoded_r: redis.Redis):
assert [3.0, 5.0] == res


@pytest.mark.redismod
@pytest.mark.experimental
async def test_tdigest_cdf(decoded_r: redis.Redis):
assert await decoded_r.tdigest().create("tDigest", 100)
Expand All @@ -444,7 +426,6 @@ async def test_tdigest_cdf(decoded_r: redis.Redis):
assert [0.1, 0.9] == [round(x, 1) for x in res]


@pytest.mark.redismod
@pytest.mark.experimental
@skip_ifmodversion_lt("2.4.0", "bf")
async def test_tdigest_trimmed_mean(decoded_r: redis.Redis):
Expand All @@ -455,7 +436,6 @@ async def test_tdigest_trimmed_mean(decoded_r: redis.Redis):
assert 4.5 == await decoded_r.tdigest().trimmed_mean("tDigest", 0.4, 0.5)


@pytest.mark.redismod
@pytest.mark.experimental
async def test_tdigest_rank(decoded_r: redis.Redis):
assert await decoded_r.tdigest().create("t-digest", 500)
Expand All @@ -466,7 +446,6 @@ async def test_tdigest_rank(decoded_r: redis.Redis):
assert [-1, 20, 9] == await decoded_r.tdigest().rank("t-digest", -20, 20, 9)


@pytest.mark.redismod
@pytest.mark.experimental
async def test_tdigest_revrank(decoded_r: redis.Redis):
assert await decoded_r.tdigest().create("t-digest", 500)
Expand All @@ -476,7 +455,6 @@ async def test_tdigest_revrank(decoded_r: redis.Redis):
assert [-1, 19, 9] == await decoded_r.tdigest().revrank("t-digest", 21, 0, 10)


@pytest.mark.redismod
@pytest.mark.experimental
async def test_tdigest_byrank(decoded_r: redis.Redis):
assert await decoded_r.tdigest().create("t-digest", 500)
Expand All @@ -488,7 +466,6 @@ async def test_tdigest_byrank(decoded_r: redis.Redis):
(await decoded_r.tdigest().byrank("t-digest", -1))[0]


@pytest.mark.redismod
@pytest.mark.experimental
async def test_tdigest_byrevrank(decoded_r: redis.Redis):
assert await decoded_r.tdigest().create("t-digest", 500)
Expand All @@ -500,8 +477,7 @@ async def test_tdigest_byrevrank(decoded_r: redis.Redis):
(await decoded_r.tdigest().byrevrank("t-digest", -1))[0]


# @pytest.mark.redismod
# async def test_pipeline(decoded_r: redis.Redis):
# # async def test_pipeline(decoded_r: redis.Redis):
# pipeline = await decoded_r.bf().pipeline()
# assert not await decoded_r.bf().execute_command("get pipeline")
#
Expand Down
20 changes: 0 additions & 20 deletions tests/test_asyncio/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
from tests.conftest import skip_if_redis_enterprise


@pytest.mark.redismod
async def test_bulk(decoded_r):
with pytest.raises(NotImplementedError):
await decoded_r.graph().bulk()
await decoded_r.graph().bulk(foo="bar!")


@pytest.mark.redismod
async def test_graph_creation(decoded_r: redis.Redis):
graph = decoded_r.graph()

Expand Down Expand Up @@ -58,7 +56,6 @@ async def test_graph_creation(decoded_r: redis.Redis):
await graph.delete()


@pytest.mark.redismod
async def test_array_functions(decoded_r: redis.Redis):
graph = decoded_r.graph()

Expand All @@ -81,7 +78,6 @@ async def test_array_functions(decoded_r: redis.Redis):
assert [a] == result.result_set[0][0]


@pytest.mark.redismod
async def test_path(decoded_r: redis.Redis):
node0 = Node(node_id=0, label="L1")
node1 = Node(node_id=1, label="L1")
Expand All @@ -101,7 +97,6 @@ async def test_path(decoded_r: redis.Redis):
assert expected_results == result.result_set


@pytest.mark.redismod
async def test_param(decoded_r: redis.Redis):
params = [1, 2.3, "str", True, False, None, [0, 1, 2]]
query = "RETURN $param"
Expand All @@ -111,7 +106,6 @@ async def test_param(decoded_r: redis.Redis):
assert expected_results == result.result_set


@pytest.mark.redismod
async def test_map(decoded_r: redis.Redis):
query = "RETURN {a:1, b:'str', c:NULL, d:[1,2,3], e:True, f:{x:1, y:2}}"

Expand All @@ -128,7 +122,6 @@ async def test_map(decoded_r: redis.Redis):
assert actual == expected


@pytest.mark.redismod
async def test_point(decoded_r: redis.Redis):
query = "RETURN point({latitude: 32.070794860, longitude: 34.820751118})"
expected_lat = 32.070794860
Expand All @@ -145,7 +138,6 @@ async def test_point(decoded_r: redis.Redis):
assert abs(actual["longitude"] - expected_lon) < 0.001


@pytest.mark.redismod
async def test_index_response(decoded_r: redis.Redis):
result_set = await decoded_r.graph().query("CREATE INDEX ON :person(age)")
assert 1 == result_set.indices_created
Expand All @@ -160,7 +152,6 @@ async def test_index_response(decoded_r: redis.Redis):
await decoded_r.graph().query("DROP INDEX ON :person(age)")


@pytest.mark.redismod
async def test_stringify_query_result(decoded_r: redis.Redis):
graph = decoded_r.graph()

Expand Down Expand Up @@ -214,7 +205,6 @@ async def test_stringify_query_result(decoded_r: redis.Redis):
await graph.delete()


@pytest.mark.redismod
async def test_optional_match(decoded_r: redis.Redis):
# Build a graph of form (a)-[R]->(b)
node0 = Node(node_id=0, label="L1", properties={"value": "a"})
Expand All @@ -239,7 +229,6 @@ async def test_optional_match(decoded_r: redis.Redis):
await graph.delete()


@pytest.mark.redismod
async def test_cached_execution(decoded_r: redis.Redis):
await decoded_r.graph().query("CREATE ()")

Expand All @@ -259,7 +248,6 @@ async def test_cached_execution(decoded_r: redis.Redis):
assert cached_result.cached_execution


@pytest.mark.redismod
async def test_slowlog(decoded_r: redis.Redis):
create_query = """CREATE
(:Rider {name:'Valentino Rossi'})-[:rides]->(:Team {name:'Yamaha'}),
Expand All @@ -272,7 +260,6 @@ async def test_slowlog(decoded_r: redis.Redis):
assert results[0][2] == create_query


@pytest.mark.redismod
@pytest.mark.xfail(strict=False)
async def test_query_timeout(decoded_r: redis.Redis):
# Build a sample graph with 1000 nodes.
Expand All @@ -287,7 +274,6 @@ async def test_query_timeout(decoded_r: redis.Redis):
assert False is False


@pytest.mark.redismod
async def test_read_only_query(decoded_r: redis.Redis):
with pytest.raises(Exception):
# Issue a write query, specifying read-only true,
Expand All @@ -296,7 +282,6 @@ async def test_read_only_query(decoded_r: redis.Redis):
assert False is False


@pytest.mark.redismod
async def test_profile(decoded_r: redis.Redis):
q = """UNWIND range(1, 3) AS x CREATE (p:Person {v:x})"""
profile = (await decoded_r.graph().profile(q)).result_set
Expand All @@ -311,7 +296,6 @@ async def test_profile(decoded_r: redis.Redis):
assert "Node By Label Scan | (p:Person) | Records produced: 3" in profile


@pytest.mark.redismod
@skip_if_redis_enterprise()
async def test_config(decoded_r: redis.Redis):
config_name = "RESULTSET_SIZE"
Expand Down Expand Up @@ -343,7 +327,6 @@ async def test_config(decoded_r: redis.Redis):
await decoded_r.graph().config("RESULTSET_SIZE", -100, set=True)


@pytest.mark.redismod
@pytest.mark.onlynoncluster
async def test_list_keys(decoded_r: redis.Redis):
result = await decoded_r.graph().list_keys()
Expand All @@ -367,7 +350,6 @@ async def test_list_keys(decoded_r: redis.Redis):
assert result == []


@pytest.mark.redismod
async def test_multi_label(decoded_r: redis.Redis):
redis_graph = decoded_r.graph("g")

Expand All @@ -393,7 +375,6 @@ async def test_multi_label(decoded_r: redis.Redis):
assert True


@pytest.mark.redismod
async def test_execution_plan(decoded_r: redis.Redis):
redis_graph = decoded_r.graph("execution_plan")
create_query = """CREATE
Expand All @@ -412,7 +393,6 @@ async def test_execution_plan(decoded_r: redis.Redis):
await redis_graph.delete()


@pytest.mark.redismod
async def test_explain(decoded_r: redis.Redis):
redis_graph = decoded_r.graph("execution_plan")
# graph creation / population
Expand Down

0 comments on commit 8e5020e

Please sign in to comment.