Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sync modules (except search) tests to cluster CI #2850

Merged
merged 14 commits into from
Aug 3, 2023
12 changes: 6 additions & 6 deletions redis/commands/bf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from redis._parsers.helpers import bool_ok

from ..helpers import parse_to_list
from ..helpers import get_protocol_version, parse_to_list
from .commands import * # noqa
from .info import BFInfo, CFInfo, CMSInfo, TDigestInfo, TopKInfo

Expand Down Expand Up @@ -108,7 +108,7 @@ def __init__(self, client, **kwargs):
self.commandmixin = CMSCommands
self.execute_command = client.execute_command

if self.client.connection_pool.connection_kwargs.get("protocol") in ["3", 3]:
if get_protocol_version(self.client) in ["3", 3]:
_MODULE_CALLBACKS.update(_RESP3_MODULE_CALLBACKS)
else:
_MODULE_CALLBACKS.update(_RESP2_MODULE_CALLBACKS)
Expand Down Expand Up @@ -139,7 +139,7 @@ def __init__(self, client, **kwargs):
self.commandmixin = TOPKCommands
self.execute_command = client.execute_command

if self.client.connection_pool.connection_kwargs.get("protocol") in ["3", 3]:
if get_protocol_version(self.client) in ["3", 3]:
_MODULE_CALLBACKS.update(_RESP3_MODULE_CALLBACKS)
else:
_MODULE_CALLBACKS.update(_RESP2_MODULE_CALLBACKS)
Expand Down Expand Up @@ -174,7 +174,7 @@ def __init__(self, client, **kwargs):
self.commandmixin = CFCommands
self.execute_command = client.execute_command

if self.client.connection_pool.connection_kwargs.get("protocol") in ["3", 3]:
if get_protocol_version(self.client) in ["3", 3]:
_MODULE_CALLBACKS.update(_RESP3_MODULE_CALLBACKS)
else:
_MODULE_CALLBACKS.update(_RESP2_MODULE_CALLBACKS)
Expand Down Expand Up @@ -210,7 +210,7 @@ def __init__(self, client, **kwargs):
self.commandmixin = TDigestCommands
self.execute_command = client.execute_command

if self.client.connection_pool.connection_kwargs.get("protocol") in ["3", 3]:
if get_protocol_version(self.client) in ["3", 3]:
_MODULE_CALLBACKS.update(_RESP3_MODULE_CALLBACKS)
else:
_MODULE_CALLBACKS.update(_RESP2_MODULE_CALLBACKS)
Expand Down Expand Up @@ -244,7 +244,7 @@ def __init__(self, client, **kwargs):
self.commandmixin = BFCommands
self.execute_command = client.execute_command

if self.client.connection_pool.connection_kwargs.get("protocol") in ["3", 3]:
if get_protocol_version(self.client) in ["3", 3]:
_MODULE_CALLBACKS.update(_RESP3_MODULE_CALLBACKS)
else:
_MODULE_CALLBACKS.update(_RESP2_MODULE_CALLBACKS)
Expand Down
8 changes: 8 additions & 0 deletions redis/commands/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import string
from typing import List, Tuple

import redis
from redis.typing import KeysT, KeyT


Expand Down Expand Up @@ -156,3 +157,10 @@ def stringify_param_value(value):
return f'{{{",".join(f"{k}:{stringify_param_value(v)}" for k, v in value.items())}}}' # noqa
else:
return str(value)


def get_protocol_version(client):
dvora-h marked this conversation as resolved.
Show resolved Hide resolved
if isinstance(client, redis.Redis) or isinstance(client, redis.asyncio.Redis):
return client.connection_pool.connection_kwargs.get("protocol")
elif isinstance(client, redis.cluster.AbstractRedisCluster):
return client.nodes_manager.connection_kwargs.get("protocol")
13 changes: 4 additions & 9 deletions redis/commands/json/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import redis

from ..helpers import nativestr
from ..helpers import get_protocol_version, nativestr
from .commands import JSONCommands
from .decoders import bulk_of_jsons, decode_list

Expand Down Expand Up @@ -34,6 +34,7 @@ def __init__(
self._MODULE_CALLBACKS = {
"JSON.ARRPOP": self._decode,
"JSON.DEBUG": self._decode,
"JSON.GET": self._decode,
"JSON.MERGE": lambda r: r and nativestr(r) == "OK",
"JSON.MGET": bulk_of_jsons(self._decode),
"JSON.MSET": lambda r: r and nativestr(r) == "OK",
Expand Down Expand Up @@ -61,19 +62,13 @@ def __init__(
"JSON.TOGGLE": self._decode,
}

_RESP3_MODULE_CALLBACKS = {
"JSON.GET": lambda response: [
[self._decode(r) for r in res] for res in response
]
if response
else response
}
_RESP3_MODULE_CALLBACKS = {}

self.client = client
self.execute_command = client.execute_command
self.MODULE_VERSION = version

if self.client.connection_pool.connection_kwargs.get("protocol") in ["3", 3]:
if get_protocol_version(self.client) in ["3", 3]:
self._MODULE_CALLBACKS.update(_RESP3_MODULE_CALLBACKS)
else:
self._MODULE_CALLBACKS.update(_RESP2_MODULE_CALLBACKS)
Expand Down
4 changes: 2 additions & 2 deletions redis/commands/timeseries/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import redis
from redis._parsers.helpers import bool_ok

from ..helpers import parse_to_list
from ..helpers import get_protocol_version, parse_to_list
from .commands import (
ALTER_CMD,
CREATE_CMD,
Expand Down Expand Up @@ -56,7 +56,7 @@ def __init__(self, client=None, **kwargs):
self.client = client
self.execute_command = client.execute_command

if self.client.connection_pool.connection_kwargs.get("protocol") in ["3", 3]:
if get_protocol_version(self.client) in ["3", 3]:
self._MODULE_CALLBACKS.update(_RESP3_MODULE_CALLBACKS)
else:
self._MODULE_CALLBACKS.update(_RESP2_MODULE_CALLBACKS)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_asyncio/test_bloom.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ async def test_tdigest_reset(decoded_r: redis.Redis):


@pytest.mark.redismod
@pytest.mark.experimental
@pytest.mark.onlynoncluster
async def test_tdigest_merge(decoded_r: redis.Redis):
assert await decoded_r.tdigest().create("to-tDigest", 10)
assert await decoded_r.tdigest().create("from-tDigest", 10)
Expand Down
1 change: 1 addition & 0 deletions tests/test_asyncio/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ async def test_mgetshouldsucceed(decoded_r: redis.Redis):


@pytest.mark.redismod
@pytest.mark.onlynoncluster
@skip_ifmodversion_lt("2.6.0", "ReJSON")
async def test_mset(decoded_r: redis.Redis):
await decoded_r.json().mset(
Expand Down
29 changes: 2 additions & 27 deletions tests/test_bloom.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def client(decoded_r):
return decoded_r


@pytest.mark.redismod
def test_create(client):
"""Test CREATE/RESERVE calls"""
assert client.bf().create("bloom", 0.01, 1000)
Expand All @@ -39,7 +38,6 @@ def test_create(client):
assert client.topk().reserve("topk", 5, 100, 5, 0.9)


@pytest.mark.redismod
def test_bf_reserve(client):
"""Testing BF.RESERVE"""
assert client.bf().reserve("bloom", 0.01, 1000)
Expand All @@ -54,13 +52,11 @@ def test_bf_reserve(client):
assert client.topk().reserve("topk", 5, 100, 5, 0.9)


@pytest.mark.redismod
@pytest.mark.experimental
def test_tdigest_create(client):
assert client.tdigest().create("tDigest", 100)


@pytest.mark.redismod
def test_bf_add(client):
assert client.bf().create("bloom", 0.01, 1000)
assert 1 == client.bf().add("bloom", "foo")
Expand All @@ -73,7 +69,6 @@ def test_bf_add(client):
assert [1, 0] == intlist(client.bf().mexists("bloom", "foo", "noexist"))


@pytest.mark.redismod
def test_bf_insert(client):
assert client.bf().create("bloom", 0.01, 1000)
assert [1] == intlist(client.bf().insert("bloom", ["foo"]))
Expand Down Expand Up @@ -104,7 +99,6 @@ def test_bf_insert(client):
)


@pytest.mark.redismod
def test_bf_scandump_and_loadchunk(client):
# Store a filter
client.bf().create("myBloom", "0.0001", "1000")
Expand Down Expand Up @@ -156,7 +150,6 @@ def do_verify():
client.bf().create("myBloom", "0.0001", "10000000")


@pytest.mark.redismod
def test_bf_info(client):
expansion = 4
# Store a filter
Expand Down Expand Up @@ -188,7 +181,6 @@ def test_bf_info(client):
assert True


@pytest.mark.redismod
def test_bf_card(client):
# return 0 if the key does not exist
assert client.bf().card("not_exist") == 0
Expand All @@ -203,7 +195,6 @@ def test_bf_card(client):
client.bf().card("setKey")


@pytest.mark.redismod
def test_cf_add_and_insert(client):
assert client.cf().create("cuckoo", 1000)
assert client.cf().add("cuckoo", "filter")
Expand All @@ -229,7 +220,6 @@ def test_cf_add_and_insert(client):
)


@pytest.mark.redismod
def test_cf_exists_and_del(client):
assert client.cf().create("cuckoo", 1000)
assert client.cf().add("cuckoo", "filter")
Expand All @@ -242,7 +232,6 @@ def test_cf_exists_and_del(client):
assert 0 == client.cf().count("cuckoo", "filter")


@pytest.mark.redismod
def test_cms(client):
assert client.cms().initbydim("dim", 1000, 5)
assert client.cms().initbyprob("prob", 0.01, 0.01)
Expand All @@ -258,7 +247,6 @@ def test_cms(client):
assert 25 == info["count"]


@pytest.mark.redismod
@pytest.mark.onlynoncluster
def test_cms_merge(client):
assert client.cms().initbydim("A", 1000, 5)
Expand All @@ -276,7 +264,6 @@ def test_cms_merge(client):
assert [16, 15, 21] == client.cms().query("C", "foo", "bar", "baz")


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


@pytest.mark.redismod
def test_topk_incrby(client):
client.flushdb()
assert client.topk().reserve("topk", 3, 10, 3, 1)
Expand All @@ -370,7 +356,6 @@ def test_topk_incrby(client):
)


@pytest.mark.redismod
@pytest.mark.experimental
def test_tdigest_reset(client):
assert client.tdigest().create("tDigest", 10)
Expand All @@ -387,8 +372,7 @@ def test_tdigest_reset(client):
)


@pytest.mark.redismod
@pytest.mark.experimental
@pytest.mark.onlynoncluster
def test_tdigest_merge(client):
assert client.tdigest().create("to-tDigest", 10)
assert client.tdigest().create("from-tDigest", 10)
Expand All @@ -415,7 +399,6 @@ def test_tdigest_merge(client):
assert 4.0 == client.tdigest().max("to-tDigest")


@pytest.mark.redismod
@pytest.mark.experimental
def test_tdigest_min_and_max(client):
assert client.tdigest().create("tDigest", 100)
Expand All @@ -426,7 +409,6 @@ def test_tdigest_min_and_max(client):
assert 1 == client.tdigest().min("tDigest")


@pytest.mark.redismod
@pytest.mark.experimental
@skip_ifmodversion_lt("2.4.0", "bf")
def test_tdigest_quantile(client):
Expand All @@ -448,7 +430,6 @@ def test_tdigest_quantile(client):
assert [3.0, 5.0] == client.tdigest().quantile("t-digest", 0.5, 0.8)


@pytest.mark.redismod
@pytest.mark.experimental
def test_tdigest_cdf(client):
assert client.tdigest().create("tDigest", 100)
Expand All @@ -460,7 +441,6 @@ def test_tdigest_cdf(client):
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")
def test_tdigest_trimmed_mean(client):
Expand All @@ -471,7 +451,6 @@ def test_tdigest_trimmed_mean(client):
assert 4.5 == client.tdigest().trimmed_mean("tDigest", 0.4, 0.5)


@pytest.mark.redismod
@pytest.mark.experimental
def test_tdigest_rank(client):
assert client.tdigest().create("t-digest", 500)
Expand All @@ -482,7 +461,6 @@ def test_tdigest_rank(client):
assert [-1, 20, 9] == client.tdigest().rank("t-digest", -20, 20, 9)


@pytest.mark.redismod
@pytest.mark.experimental
def test_tdigest_revrank(client):
assert client.tdigest().create("t-digest", 500)
Expand All @@ -492,7 +470,6 @@ def test_tdigest_revrank(client):
assert [-1, 19, 9] == client.tdigest().revrank("t-digest", 21, 0, 10)


@pytest.mark.redismod
@pytest.mark.experimental
def test_tdigest_byrank(client):
assert client.tdigest().create("t-digest", 500)
Expand All @@ -504,7 +481,6 @@ def test_tdigest_byrank(client):
client.tdigest().byrank("t-digest", -1)[0]


@pytest.mark.redismod
@pytest.mark.experimental
def test_tdigest_byrevrank(client):
assert client.tdigest().create("t-digest", 500)
Expand All @@ -516,8 +492,7 @@ def test_tdigest_byrevrank(client):
client.tdigest().byrevrank("t-digest", -1)[0]


# @pytest.mark.redismod
# def test_pipeline(client):
# # def test_pipeline(client):
# pipeline = client.bf().pipeline()
# assert not client.bf().execute_command("get pipeline")
#
Expand Down
Loading
Loading