Skip to content

Commit aa22225

Browse files
authored
Fix bug with partial Hiredis availability (#3400)
* Fix bug with partial Hiredis availability * Added yes flag * Codestyl fixes * Removed redundant check * Removed redundant checks associated with pack command * Updated condition to check the actual flag * Removed unused import
1 parent c31849c commit aa22225

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

Diff for: .github/workflows/integration.yaml

+33
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,21 @@ jobs:
9090
invoke ${{matrix.test-type}}-tests
9191
ls -1
9292
93+
- name: Run tests against hiredis < 3.0.0
94+
if: ${{ matrix.connection-type == 'hiredis' && matrix.python-version == '3.12'}}
95+
run: |
96+
pip uninstall hiredis -y
97+
pip install -U setuptools wheel
98+
pip install -r requirements.txt
99+
pip install -r dev_requirements.txt
100+
if [ "${{matrix.connection-type}}" == "hiredis" ]; then
101+
pip install "hiredis<3.0.0"
102+
fi
103+
invoke devenv
104+
sleep 10 # time to settle
105+
invoke ${{matrix.test-type}}-tests
106+
ls -1
107+
93108
- name: Upload test results and profiling data
94109
uses: actions/upload-artifact@v4
95110
with:
@@ -145,6 +160,24 @@ jobs:
145160
invoke ${{matrix.test-type}}-tests --protocol=3
146161
fi
147162
163+
- name: Run tests against hiredis < 3.0.0
164+
if: ${{ matrix.connection-type == 'hiredis' && matrix.python-version == '3.12'}}
165+
run: |
166+
pip uninstall hiredis -y
167+
pip install -U setuptools wheel
168+
pip install -r requirements.txt
169+
pip install -r dev_requirements.txt
170+
if [ "${{matrix.connection-type}}" == "hiredis" ]; then
171+
pip install "hiredis<3.0.0"
172+
fi
173+
invoke devenv
174+
sleep 10 # time to settle
175+
if [ "${{matrix.event-loop}}" == "uvloop" ]; then
176+
invoke ${{matrix.test-type}}-tests --uvloop --protocol=3
177+
else
178+
invoke ${{matrix.test-type}}-tests --protocol=3
179+
fi
180+
148181
- name: Upload test results and profiling data
149182
uses: actions/upload-artifact@v4
150183
with:

Diff for: redis/connection.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
from .utils import (
3939
CRYPTOGRAPHY_AVAILABLE,
4040
HIREDIS_AVAILABLE,
41-
HIREDIS_PACK_AVAILABLE,
4241
SSL_AVAILABLE,
4342
compare_versions,
4443
ensure_string,
@@ -314,7 +313,7 @@ def __del__(self):
314313
def _construct_command_packer(self, packer):
315314
if packer is not None:
316315
return packer
317-
elif HIREDIS_PACK_AVAILABLE:
316+
elif HIREDIS_AVAILABLE:
318317
return HiredisRespSerializer()
319318
else:
320319
return PythonRespSerializer(self._buffer_cutoff, self.encoder.encode)

Diff for: redis/utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
# Only support Hiredis >= 3.0:
1010
HIREDIS_AVAILABLE = int(hiredis.__version__.split(".")[0]) >= 3
11-
HIREDIS_PACK_AVAILABLE = hasattr(hiredis, "pack_command")
11+
if not HIREDIS_AVAILABLE:
12+
raise ImportError("hiredis package should be >= 3.0.0")
1213
except ImportError:
1314
HIREDIS_AVAILABLE = False
14-
HIREDIS_PACK_AVAILABLE = False
1515

1616
try:
1717
import ssl # noqa

Diff for: tests/test_encoding.py

-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import pytest
22
import redis
3-
from redis.connection import Connection
4-
from redis.utils import HIREDIS_PACK_AVAILABLE
53

64
from .conftest import _get_client
75

@@ -75,22 +73,6 @@ def test_replace(self, request):
7573
assert r.get("a") == "foo\ufffd"
7674

7775

78-
@pytest.mark.skipif(
79-
HIREDIS_PACK_AVAILABLE,
80-
reason="Packing via hiredis does not preserve memoryviews",
81-
)
82-
class TestMemoryviewsAreNotPacked:
83-
def test_memoryviews_are_not_packed(self):
84-
c = Connection()
85-
arg = memoryview(b"some_arg")
86-
arg_list = ["SOME_COMMAND", arg]
87-
cmd = c.pack_command(*arg_list)
88-
assert cmd[1] is arg
89-
cmds = c.pack_commands([arg_list, arg_list])
90-
assert cmds[1] is arg
91-
assert cmds[3] is arg
92-
93-
9476
class TestCommandsAreNotEncoded:
9577
@pytest.fixture()
9678
def r(self, request):

0 commit comments

Comments
 (0)