Skip to content

Commit a87ce48

Browse files
authored
Merge pull request redis#32 from mkmkme/mkmkme/libvalkey
Replace hiredis dependency with libvalkey
2 parents 652669c + 51d3416 commit a87ce48

36 files changed

+178
-234
lines changed

.github/wordlist.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ firsttimersonly
8989
fo
9090
genindex
9191
gmail
92-
hiredis
9392
html
9493
http
9594
https
@@ -101,6 +100,7 @@ json
101100
keyslot
102101
keyspace
103102
kwarg
103+
libvalkey
104104
linters
105105
localhost
106106
lua

.github/workflows/integration.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
matrix:
6060
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', 'pypy-3.9', 'pypy-3.10']
6161
test-type: ['standalone', 'cluster']
62-
connection-type: ['hiredis', 'plain']
62+
connection-type: ['libvalkey', 'plain']
6363
env:
6464
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
6565
name: Python ${{ matrix.python-version }} ${{matrix.test-type}}-${{matrix.connection-type}} tests
@@ -74,8 +74,8 @@ jobs:
7474
pip install -U setuptools wheel
7575
pip install -r requirements.txt
7676
pip install -r dev_requirements.txt
77-
if [ "${{matrix.connection-type}}" == "hiredis" ]; then
78-
pip install "hiredis<3.0.0"
77+
if [ "${{matrix.connection-type}}" == "libvalkey" ]; then
78+
pip install "libvalkey>=4.0.0b1"
7979
fi
8080
invoke devenv
8181
sleep 10 # time to settle
@@ -104,10 +104,10 @@ jobs:
104104
matrix:
105105
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', 'pypy-3.9', 'pypy-3.10']
106106
test-type: ['standalone', 'cluster']
107-
connection-type: ['hiredis', 'plain']
107+
connection-type: ['libvalkey', 'plain']
108108
exclude:
109109
- test-type: 'cluster'
110-
connection-type: 'hiredis'
110+
connection-type: 'libvalkey'
111111
env:
112112
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
113113
name: RESP3 [${{ matrix.python-version }} ${{matrix.test-type}}-${{matrix.connection-type}}]
@@ -122,8 +122,8 @@ jobs:
122122
pip install -U setuptools wheel
123123
pip install -r requirements.txt
124124
pip install -r dev_requirements.txt
125-
if [ "${{matrix.connection-type}}" == "hiredis" ]; then
126-
pip install "hiredis<3.0.0"
125+
if [ "${{matrix.connection-type}}" == "libvalkey" ]; then
126+
pip install "libvalkey>=4.0.0b1"
127127
fi
128128
invoke devenv
129129
sleep 10 # time to settle

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ To install valkey-py, simply:
2727
$ pip install valkey
2828
```
2929

30-
For faster performance, install valkey with hiredis support, this provides a compiled response parser, and *for most cases* requires zero code changes.
31-
By default, if hiredis >= 1.0 is available, valkey-py will attempt to use it for response parsing.
30+
For faster performance, install valkey with libvalkey support, this provides a compiled response parser, and *for most cases* requires zero code changes.
31+
By default, if libvalkey >= 2.3.2 is available, valkey-py will attempt to use it for response parsing.
3232

3333
``` bash
34-
$ pip install "valkey[hiredis]"
34+
$ pip install "valkey[libvalkey]"
3535
```
3636

3737
## Usage

benchmarks/socket_read_size.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from base import Benchmark
22

3-
from valkey.connection import PythonParser, _HiredisParser
3+
from valkey.connection import PythonParser, _LibvalkeyParser
44

55

66
class SocketReadBenchmark(Benchmark):
77

88
ARGUMENTS = (
9-
{"name": "parser", "values": [PythonParser, _HiredisParser]},
9+
{"name": "parser", "values": [PythonParser, _LibvalkeyParser]},
1010
{
1111
"name": "value_size",
1212
"values": [10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000],

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"Programming Language :: Python :: Implementation :: PyPy",
5656
],
5757
extras_require={
58-
"hiredis": ["hiredis >=1.0.0, <3.0.0"],
58+
"libvalkey": ["libvalkey>=4.0.0b1"],
5959
"ocsp": ["cryptography>=36.0.1", "pyopenssl==20.0.1", "requests>=2.26.0"],
6060
},
6161
)

tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def all_tests(c, color=False):
4444
@task
4545
def tests(c, uvloop=False, protocol=2, color=False):
4646
"""Run the valkey-py test suite against the current python,
47-
with and without hiredis.
47+
with and without libvalkey.
4848
"""
4949
print("Starting Valkey tests")
5050
standalone_tests(c, uvloop=uvloop, protocol=protocol, color=color)

tests/test_asyncio/test_bloom.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
is_resp2_connection,
88
skip_ifmodversion_lt,
99
)
10-
from valkey.exceptions import ModuleError, ValkeyError
11-
from valkey.utils import HIREDIS_AVAILABLE
10+
from valkey.exceptions import ValkeyError
1211

1312
pytestmark = pytest.mark.skip
1413

@@ -96,10 +95,6 @@ async def do_verify():
9695

9796
await do_verify()
9897
cmds = []
99-
if HIREDIS_AVAILABLE:
100-
with pytest.raises(ModuleError):
101-
cur = await decoded_r.bf().scandump("myBloom", 0)
102-
return
10398

10499
cur = await decoded_r.bf().scandump("myBloom", 0)
105100
first = cur[0]

tests/test_asyncio/test_cache.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44
import pytest_asyncio
55
from valkey._cache import EvictionPolicy, _LocalCache
6-
from valkey.utils import HIREDIS_AVAILABLE
6+
from valkey.utils import LIBVALKEY_AVAILABLE
77

88

99
@pytest_asyncio.fixture
@@ -19,7 +19,7 @@ async def local_cache():
1919
yield _LocalCache()
2020

2121

22-
@pytest.mark.skipif(HIREDIS_AVAILABLE, reason="PythonParser only")
22+
@pytest.mark.skipif(LIBVALKEY_AVAILABLE, reason="PythonParser only")
2323
class TestLocalCache:
2424
@pytest.mark.parametrize("r", [{"cache": _LocalCache()}], indirect=True)
2525
@pytest.mark.onlynoncluster
@@ -299,7 +299,7 @@ async def test_flush_entire_cache(self, r):
299299
assert await r.get("c") == "1"
300300

301301

302-
@pytest.mark.skipif(HIREDIS_AVAILABLE, reason="PythonParser only")
302+
@pytest.mark.skipif(LIBVALKEY_AVAILABLE, reason="PythonParser only")
303303
@pytest.mark.onlycluster
304304
class TestClusterLocalCache:
305305
@pytest.mark.parametrize("r", [{"cache": _LocalCache()}], indirect=True)
@@ -368,7 +368,7 @@ async def test_execute_command_keys_not_provided(self, r):
368368
assert cache.get(("GET", "b")) is None
369369

370370

371-
@pytest.mark.skipif(HIREDIS_AVAILABLE, reason="PythonParser only")
371+
@pytest.mark.skipif(LIBVALKEY_AVAILABLE, reason="PythonParser only")
372372
@pytest.mark.onlynoncluster
373373
class TestSentinelLocalCache:
374374

tests/test_asyncio/test_cluster.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,49 +1730,49 @@ async def test_cluster_rpoplpush(self, r: ValkeyCluster) -> None:
17301730

17311731
async def test_cluster_sdiff(self, r: ValkeyCluster) -> None:
17321732
await r.sadd("{foo}a", "1", "2", "3")
1733-
assert await r.sdiff("{foo}a", "{foo}b") == {b"1", b"2", b"3"}
1733+
assert set(await r.sdiff("{foo}a", "{foo}b")) == {b"1", b"2", b"3"}
17341734
await r.sadd("{foo}b", "2", "3")
1735-
assert await r.sdiff("{foo}a", "{foo}b") == {b"1"}
1735+
assert await r.sdiff("{foo}a", "{foo}b") == [b"1"]
17361736

17371737
async def test_cluster_sdiffstore(self, r: ValkeyCluster) -> None:
17381738
await r.sadd("{foo}a", "1", "2", "3")
17391739
assert await r.sdiffstore("{foo}c", "{foo}a", "{foo}b") == 3
1740-
assert await r.smembers("{foo}c") == {b"1", b"2", b"3"}
1740+
assert set(await r.smembers("{foo}c")) == {b"1", b"2", b"3"}
17411741
await r.sadd("{foo}b", "2", "3")
17421742
assert await r.sdiffstore("{foo}c", "{foo}a", "{foo}b") == 1
1743-
assert await r.smembers("{foo}c") == {b"1"}
1743+
assert await r.smembers("{foo}c") == [b"1"]
17441744

17451745
async def test_cluster_sinter(self, r: ValkeyCluster) -> None:
17461746
await r.sadd("{foo}a", "1", "2", "3")
1747-
assert await r.sinter("{foo}a", "{foo}b") == set()
1747+
assert await r.sinter("{foo}a", "{foo}b") == []
17481748
await r.sadd("{foo}b", "2", "3")
1749-
assert await r.sinter("{foo}a", "{foo}b") == {b"2", b"3"}
1749+
assert set(await r.sinter("{foo}a", "{foo}b")) == {b"2", b"3"}
17501750

17511751
async def test_cluster_sinterstore(self, r: ValkeyCluster) -> None:
17521752
await r.sadd("{foo}a", "1", "2", "3")
17531753
assert await r.sinterstore("{foo}c", "{foo}a", "{foo}b") == 0
1754-
assert await r.smembers("{foo}c") == set()
1754+
assert await r.smembers("{foo}c") == []
17551755
await r.sadd("{foo}b", "2", "3")
17561756
assert await r.sinterstore("{foo}c", "{foo}a", "{foo}b") == 2
1757-
assert await r.smembers("{foo}c") == {b"2", b"3"}
1757+
assert set(await r.smembers("{foo}c")) == {b"2", b"3"}
17581758

17591759
async def test_cluster_smove(self, r: ValkeyCluster) -> None:
17601760
await r.sadd("{foo}a", "a1", "a2")
17611761
await r.sadd("{foo}b", "b1", "b2")
17621762
assert await r.smove("{foo}a", "{foo}b", "a1")
1763-
assert await r.smembers("{foo}a") == {b"a2"}
1764-
assert await r.smembers("{foo}b") == {b"b1", b"b2", b"a1"}
1763+
assert await r.smembers("{foo}a") == [b"a2"]
1764+
assert set(await r.smembers("{foo}b")) == {b"b1", b"b2", b"a1"}
17651765

17661766
async def test_cluster_sunion(self, r: ValkeyCluster) -> None:
17671767
await r.sadd("{foo}a", "1", "2")
17681768
await r.sadd("{foo}b", "2", "3")
1769-
assert await r.sunion("{foo}a", "{foo}b") == {b"1", b"2", b"3"}
1769+
assert set(await r.sunion("{foo}a", "{foo}b")) == {b"1", b"2", b"3"}
17701770

17711771
async def test_cluster_sunionstore(self, r: ValkeyCluster) -> None:
17721772
await r.sadd("{foo}a", "1", "2")
17731773
await r.sadd("{foo}b", "2", "3")
17741774
assert await r.sunionstore("{foo}c", "{foo}a", "{foo}b") == 3
1775-
assert await r.smembers("{foo}c") == {b"1", b"2", b"3"}
1775+
assert set(await r.smembers("{foo}c")) == {b"1", b"2", b"3"}
17761776

17771777
@skip_if_server_version_lt("6.2.0")
17781778
async def test_cluster_zdiff(self, r: ValkeyCluster) -> None:

tests/test_asyncio/test_commands.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ async def test_zscan_iter(self, r: valkey.Valkey):
14061406
async def test_sadd(self, r: valkey.Valkey):
14071407
members = {b"1", b"2", b"3"}
14081408
await r.sadd("a", *members)
1409-
assert await r.smembers("a") == members
1409+
assert set(await r.smembers("a")) == members
14101410

14111411
async def test_scard(self, r: valkey.Valkey):
14121412
await r.sadd("a", "1", "2", "3")
@@ -1415,34 +1415,34 @@ async def test_scard(self, r: valkey.Valkey):
14151415
@pytest.mark.onlynoncluster
14161416
async def test_sdiff(self, r: valkey.Valkey):
14171417
await r.sadd("a", "1", "2", "3")
1418-
assert await r.sdiff("a", "b") == {b"1", b"2", b"3"}
1418+
assert set(await r.sdiff("a", "b")) == {b"1", b"2", b"3"}
14191419
await r.sadd("b", "2", "3")
1420-
assert await r.sdiff("a", "b") == {b"1"}
1420+
assert await r.sdiff("a", "b") == [b"1"]
14211421

14221422
@pytest.mark.onlynoncluster
14231423
async def test_sdiffstore(self, r: valkey.Valkey):
14241424
await r.sadd("a", "1", "2", "3")
14251425
assert await r.sdiffstore("c", "a", "b") == 3
1426-
assert await r.smembers("c") == {b"1", b"2", b"3"}
1426+
assert set(await r.smembers("c")) == {b"1", b"2", b"3"}
14271427
await r.sadd("b", "2", "3")
14281428
assert await r.sdiffstore("c", "a", "b") == 1
1429-
assert await r.smembers("c") == {b"1"}
1429+
assert await r.smembers("c") == [b"1"]
14301430

14311431
@pytest.mark.onlynoncluster
14321432
async def test_sinter(self, r: valkey.Valkey):
14331433
await r.sadd("a", "1", "2", "3")
1434-
assert await r.sinter("a", "b") == set()
1434+
assert await r.sinter("a", "b") == []
14351435
await r.sadd("b", "2", "3")
1436-
assert await r.sinter("a", "b") == {b"2", b"3"}
1436+
assert set(await r.sinter("a", "b")) == {b"2", b"3"}
14371437

14381438
@pytest.mark.onlynoncluster
14391439
async def test_sinterstore(self, r: valkey.Valkey):
14401440
await r.sadd("a", "1", "2", "3")
14411441
assert await r.sinterstore("c", "a", "b") == 0
1442-
assert await r.smembers("c") == set()
1442+
assert await r.smembers("c") == []
14431443
await r.sadd("b", "2", "3")
14441444
assert await r.sinterstore("c", "a", "b") == 2
1445-
assert await r.smembers("c") == {b"2", b"3"}
1445+
assert set(await r.smembers("c")) == {b"2", b"3"}
14461446

14471447
async def test_sismember(self, r: valkey.Valkey):
14481448
await r.sadd("a", "1", "2", "3")
@@ -1453,22 +1453,22 @@ async def test_sismember(self, r: valkey.Valkey):
14531453

14541454
async def test_smembers(self, r: valkey.Valkey):
14551455
await r.sadd("a", "1", "2", "3")
1456-
assert await r.smembers("a") == {b"1", b"2", b"3"}
1456+
assert set(await r.smembers("a")) == {b"1", b"2", b"3"}
14571457

14581458
@pytest.mark.onlynoncluster
14591459
async def test_smove(self, r: valkey.Valkey):
14601460
await r.sadd("a", "a1", "a2")
14611461
await r.sadd("b", "b1", "b2")
14621462
assert await r.smove("a", "b", "a1")
1463-
assert await r.smembers("a") == {b"a2"}
1464-
assert await r.smembers("b") == {b"b1", b"b2", b"a1"}
1463+
assert await r.smembers("a") == [b"a2"]
1464+
assert set(await r.smembers("b")) == {b"b1", b"b2", b"a1"}
14651465

14661466
async def test_spop(self, r: valkey.Valkey):
14671467
s = [b"1", b"2", b"3"]
14681468
await r.sadd("a", *s)
14691469
value = await r.spop("a")
14701470
assert value in s
1471-
assert await r.smembers("a") == set(s) - {value}
1471+
assert set(await r.smembers("a")) == set(s) - {value}
14721472

14731473
@skip_if_server_version_lt("3.2.0")
14741474
async def test_spop_multi_value(self, r: valkey.Valkey):
@@ -1481,9 +1481,7 @@ async def test_spop_multi_value(self, r: valkey.Valkey):
14811481
assert value in s
14821482

14831483
response = await r.spop("a", 1)
1484-
assert_resp_response(
1485-
r, response, list(set(s) - set(values)), set(s) - set(values)
1486-
)
1484+
assert set(response) == set(s) - set(values)
14871485

14881486
async def test_srandmember(self, r: valkey.Valkey):
14891487
s = [b"1", b"2", b"3"]
@@ -1502,20 +1500,20 @@ async def test_srem(self, r: valkey.Valkey):
15021500
await r.sadd("a", "1", "2", "3", "4")
15031501
assert await r.srem("a", "5") == 0
15041502
assert await r.srem("a", "2", "4") == 2
1505-
assert await r.smembers("a") == {b"1", b"3"}
1503+
assert set(await r.smembers("a")) == {b"1", b"3"}
15061504

15071505
@pytest.mark.onlynoncluster
15081506
async def test_sunion(self, r: valkey.Valkey):
15091507
await r.sadd("a", "1", "2")
15101508
await r.sadd("b", "2", "3")
1511-
assert await r.sunion("a", "b") == {b"1", b"2", b"3"}
1509+
assert set(await r.sunion("a", "b")) == {b"1", b"2", b"3"}
15121510

15131511
@pytest.mark.onlynoncluster
15141512
async def test_sunionstore(self, r: valkey.Valkey):
15151513
await r.sadd("a", "1", "2")
15161514
await r.sadd("b", "2", "3")
15171515
assert await r.sunionstore("c", "a", "b") == 3
1518-
assert await r.smembers("c") == {b"1", b"2", b"3"}
1516+
assert set(await r.smembers("c")) == {b"1", b"2", b"3"}
15191517

15201518
# SORTED SET COMMANDS
15211519
async def test_zadd(self, r: valkey.Valkey):

0 commit comments

Comments
 (0)