From 22038a6387546d9e44e3bc19b059d2cd3f80c95d Mon Sep 17 00:00:00 2001 From: vladvildanov Date: Wed, 2 Oct 2024 17:01:35 +0300 Subject: [PATCH 1/7] Fix bug with partial Hiredis availability --- .github/workflows/integration.yaml | 33 ++++++++++++++++++++++++++++++ redis/utils.py | 4 ++++ 2 files changed, 37 insertions(+) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index b10edf2fb4..f370ca8ed1 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -90,6 +90,21 @@ jobs: invoke ${{matrix.test-type}}-tests ls -1 + - name: Run tests against hiredis < 3.0.0 + if: ${{ matrix.connection-type == 'hiredis' && matrix.python-version == '3.12'}} + run: | + pip uninstall hiredis + pip install -U setuptools wheel + pip install -r requirements.txt + pip install -r dev_requirements.txt + if [ "${{matrix.connection-type}}" == "hiredis" ]; then + pip install "hiredis<3.0.0" + fi + invoke devenv + sleep 10 # time to settle + invoke ${{matrix.test-type}}-tests + ls -1 + - name: Upload test results and profiling data uses: actions/upload-artifact@v4 with: @@ -145,6 +160,24 @@ jobs: invoke ${{matrix.test-type}}-tests --protocol=3 fi + - name: Run tests against hiredis < 3.0.0 + if: ${{ matrix.connection-type == 'hiredis' && matrix.python-version == '3.12'}} + run: | + pip uninstall hiredis + pip install -U setuptools wheel + pip install -r requirements.txt + pip install -r dev_requirements.txt + if [ "${{matrix.connection-type}}" == "hiredis" ]; then + pip install "hiredis<3.0.0" + fi + invoke devenv + sleep 10 # time to settle + if [ "${{matrix.event-loop}}" == "uvloop" ]; then + invoke ${{matrix.test-type}}-tests --uvloop --protocol=3 + else + invoke ${{matrix.test-type}}-tests --protocol=3 + fi + - name: Upload test results and profiling data uses: actions/upload-artifact@v4 with: diff --git a/redis/utils.py b/redis/utils.py index b4e9afb054..e40ca2c46d 100644 --- a/redis/utils.py +++ b/redis/utils.py @@ -8,7 +8,11 @@ # Only support Hiredis >= 3.0: HIREDIS_AVAILABLE = int(hiredis.__version__.split(".")[0]) >= 3 + if not HIREDIS_AVAILABLE: + raise ImportError("hiredis package should be >= 3.0.0") HIREDIS_PACK_AVAILABLE = hasattr(hiredis, "pack_command") + if not HIREDIS_PACK_AVAILABLE: + raise ImportError("pack_command is not available in the current version of hiredis.") except ImportError: HIREDIS_AVAILABLE = False HIREDIS_PACK_AVAILABLE = False From c1ca58678936c9d6f286e2a1e665282f4b3f4b11 Mon Sep 17 00:00:00 2001 From: vladvildanov Date: Wed, 2 Oct 2024 17:11:26 +0300 Subject: [PATCH 2/7] Added yes flag --- .github/workflows/integration.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index f370ca8ed1..ed969d11f1 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -93,7 +93,7 @@ jobs: - name: Run tests against hiredis < 3.0.0 if: ${{ matrix.connection-type == 'hiredis' && matrix.python-version == '3.12'}} run: | - pip uninstall hiredis + pip uninstall hiredis -y pip install -U setuptools wheel pip install -r requirements.txt pip install -r dev_requirements.txt @@ -163,7 +163,7 @@ jobs: - name: Run tests against hiredis < 3.0.0 if: ${{ matrix.connection-type == 'hiredis' && matrix.python-version == '3.12'}} run: | - pip uninstall hiredis + pip uninstall hiredis -y pip install -U setuptools wheel pip install -r requirements.txt pip install -r dev_requirements.txt From 4ff84211cdd2253ab80712a03a570bc1f0b8dcad Mon Sep 17 00:00:00 2001 From: vladvildanov Date: Wed, 2 Oct 2024 17:18:48 +0300 Subject: [PATCH 3/7] Codestyl fixes --- redis/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/redis/utils.py b/redis/utils.py index e40ca2c46d..5632bb18a7 100644 --- a/redis/utils.py +++ b/redis/utils.py @@ -12,7 +12,9 @@ raise ImportError("hiredis package should be >= 3.0.0") HIREDIS_PACK_AVAILABLE = hasattr(hiredis, "pack_command") if not HIREDIS_PACK_AVAILABLE: - raise ImportError("pack_command is not available in the current version of hiredis.") + raise ImportError( + "pack_command is not available in the current version of hiredis." + ) except ImportError: HIREDIS_AVAILABLE = False HIREDIS_PACK_AVAILABLE = False From 9c2caf82dc5306a9f5a1f000f23dc1bd5c2ea96d Mon Sep 17 00:00:00 2001 From: vladvildanov Date: Wed, 2 Oct 2024 18:19:06 +0300 Subject: [PATCH 4/7] Removed redundant check --- redis/utils.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/redis/utils.py b/redis/utils.py index 5632bb18a7..85c5fd2e48 100644 --- a/redis/utils.py +++ b/redis/utils.py @@ -10,11 +10,6 @@ HIREDIS_AVAILABLE = int(hiredis.__version__.split(".")[0]) >= 3 if not HIREDIS_AVAILABLE: raise ImportError("hiredis package should be >= 3.0.0") - HIREDIS_PACK_AVAILABLE = hasattr(hiredis, "pack_command") - if not HIREDIS_PACK_AVAILABLE: - raise ImportError( - "pack_command is not available in the current version of hiredis." - ) except ImportError: HIREDIS_AVAILABLE = False HIREDIS_PACK_AVAILABLE = False From a5dde0f1558cb53082a4004f6726f37a8cd03e11 Mon Sep 17 00:00:00 2001 From: vladvildanov Date: Wed, 2 Oct 2024 18:28:12 +0300 Subject: [PATCH 5/7] Removed redundant checks associated with pack command --- redis/connection.py | 3 --- redis/utils.py | 1 - tests/test_encoding.py | 17 ----------------- 3 files changed, 21 deletions(-) diff --git a/redis/connection.py b/redis/connection.py index 6aae2101c2..1b0985ca9f 100644 --- a/redis/connection.py +++ b/redis/connection.py @@ -38,7 +38,6 @@ from .utils import ( CRYPTOGRAPHY_AVAILABLE, HIREDIS_AVAILABLE, - HIREDIS_PACK_AVAILABLE, SSL_AVAILABLE, compare_versions, ensure_string, @@ -314,8 +313,6 @@ def __del__(self): def _construct_command_packer(self, packer): if packer is not None: return packer - elif HIREDIS_PACK_AVAILABLE: - return HiredisRespSerializer() else: return PythonRespSerializer(self._buffer_cutoff, self.encoder.encode) diff --git a/redis/utils.py b/redis/utils.py index 85c5fd2e48..8693fb3c8f 100644 --- a/redis/utils.py +++ b/redis/utils.py @@ -12,7 +12,6 @@ raise ImportError("hiredis package should be >= 3.0.0") except ImportError: HIREDIS_AVAILABLE = False - HIREDIS_PACK_AVAILABLE = False try: import ssl # noqa diff --git a/tests/test_encoding.py b/tests/test_encoding.py index 331cd5108c..229200ae9b 100644 --- a/tests/test_encoding.py +++ b/tests/test_encoding.py @@ -1,7 +1,6 @@ import pytest import redis from redis.connection import Connection -from redis.utils import HIREDIS_PACK_AVAILABLE from .conftest import _get_client @@ -75,22 +74,6 @@ def test_replace(self, request): assert r.get("a") == "foo\ufffd" -@pytest.mark.skipif( - HIREDIS_PACK_AVAILABLE, - reason="Packing via hiredis does not preserve memoryviews", -) -class TestMemoryviewsAreNotPacked: - def test_memoryviews_are_not_packed(self): - c = Connection() - arg = memoryview(b"some_arg") - arg_list = ["SOME_COMMAND", arg] - cmd = c.pack_command(*arg_list) - assert cmd[1] is arg - cmds = c.pack_commands([arg_list, arg_list]) - assert cmds[1] is arg - assert cmds[3] is arg - - class TestCommandsAreNotEncoded: @pytest.fixture() def r(self, request): From 47799659fcfbeb8d86e7b37227ba6b4d3bf26b1d Mon Sep 17 00:00:00 2001 From: vladvildanov Date: Thu, 3 Oct 2024 15:30:20 +0300 Subject: [PATCH 6/7] Updated condition to check the actual flag --- redis/connection.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/redis/connection.py b/redis/connection.py index 1b0985ca9f..40f2d29722 100644 --- a/redis/connection.py +++ b/redis/connection.py @@ -313,6 +313,8 @@ def __del__(self): def _construct_command_packer(self, packer): if packer is not None: return packer + elif HIREDIS_AVAILABLE: + return HiredisRespSerializer() else: return PythonRespSerializer(self._buffer_cutoff, self.encoder.encode) From 930fa2d6f2402e34672ac8aa69c6e47684a9a65c Mon Sep 17 00:00:00 2001 From: vladvildanov Date: Thu, 3 Oct 2024 15:32:18 +0300 Subject: [PATCH 7/7] Removed unused import --- tests/test_encoding.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_encoding.py b/tests/test_encoding.py index 229200ae9b..0fcb256cfb 100644 --- a/tests/test_encoding.py +++ b/tests/test_encoding.py @@ -1,6 +1,5 @@ import pytest import redis -from redis.connection import Connection from .conftest import _get_client