From ae672c563743e559e8ea46e20563ac52b00d006c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Mus=C3=ADlek?= Date: Tue, 7 Nov 2023 15:56:01 +0100 Subject: [PATCH] fixup! Add cluster option to result backend --- .github/workflows/test.yml | 32 ++----------------- docker-compose.yml | 60 +++++++++++++++++++++++++++++++++++ taskiq_redis/redis_backend.py | 2 +- tests/conftest.py | 4 +-- 4 files changed, 65 insertions(+), 33 deletions(-) create mode 100644 docker-compose.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5108ca5..4f7d58f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,42 +30,14 @@ jobs: - name: Run lint check run: poetry run pre-commit run -a ${{ matrix.cmd }} pytest: - services: - redis: - image: bitnami/redis:6.2.5 - env: - ALLOW_EMPTY_PASSWORD: "yes" - options: >- - --health-cmd="redis-cli ping" - --health-interval=5s - --health-timeout=5s - --health-retries=30 - ports: - - 6379:6379 - redis-cluster: - image: bitnami/redis-cluster:6.2.5 - env: - ALLOW_EMPTY_PASSWORD: "yes" - REDIS_NODES: "localhost" - options: >- - --health-cmd="redis-cli ping" - --health-interval=5s - --health-timeout=5s - --health-retries=30 - ports: - - 7000:6379 strategy: matrix: py_version: ["3.8", "3.9", "3.10", "3.11", "3.12"] runs-on: "ubuntu-latest" steps: - uses: actions/checkout@v4 - - uses: shogo82148/actions-setup-redis@v1 - with: - redis-version: "6.x" - auto-start: false - - name: Set up single-node Redis cluster - run: redis-cli -h localhost -p 7000 --cluster-yes CLUSTER ADDSLOTS {0..16383} + - name: Set up Redis instance and Redis cluster + run: docker-compose up -d - name: Set up Python uses: actions/setup-python@v2 with: diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f7810f2 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,60 @@ +version: '3.2' + +services: + redis: + image: bitnami/redis:6.2.5 + environment: + ALLOW_EMPTY_PASSWORD: "yes" + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 5s + timeout: 5s + retries: 3 + start_period: 10s + ports: + - 7000:6379 + redis-node-0: + image: docker.io/bitnami/redis-cluster:7.2 + environment: + ALLOW_EMPTY_PASSWORD: "yes" + REDIS_NODES: "redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5" + + redis-node-1: + image: docker.io/bitnami/redis-cluster:7.2 + environment: + ALLOW_EMPTY_PASSWORD: "yes" + REDIS_NODES: "redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5" + + redis-node-2: + image: docker.io/bitnami/redis-cluster:7.2 + environment: + ALLOW_EMPTY_PASSWORD: "yes" + REDIS_NODES: "redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5" + + redis-node-3: + image: docker.io/bitnami/redis-cluster:7.2 + environment: + ALLOW_EMPTY_PASSWORD: "yes" + REDIS_NODES: "redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5" + + redis-node-4: + image: docker.io/bitnami/redis-cluster:7.2 + environment: + ALLOW_EMPTY_PASSWORD: "yes" + REDIS_NODES: "redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5" + + redis-node-5: + image: docker.io/bitnami/redis-cluster:7.2 + depends_on: + - redis-node-0 + - redis-node-1 + - redis-node-2 + - redis-node-3 + - redis-node-4 + environment: + ALLOW_EMPTY_PASSWORD: "yes" + REDIS_NODES: "redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5" + REDIS_CLUSTER_REPLICAS: 1 + REDIS_CLUSTER_CREATOR: "yes" + ports: + - 7001:6379 diff --git a/taskiq_redis/redis_backend.py b/taskiq_redis/redis_backend.py index 2e0cf3c..3a0810d 100644 --- a/taskiq_redis/redis_backend.py +++ b/taskiq_redis/redis_backend.py @@ -183,7 +183,7 @@ def __init__( async def shutdown(self) -> None: """Closes redis connection.""" - await self.redis.close() + await self.redis.aclose() # type: ignore[attr-defined] await super().shutdown() async def set_result( diff --git a/tests/conftest.py b/tests/conftest.py index 3a125ce..dcccb79 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -25,7 +25,7 @@ def redis_url() -> str: :return: URL string. """ - return os.environ.get("TEST_REDIS_URL", "redis://localhost") + return os.environ.get("TEST_REDIS_URL", "redis://localhost:7000") @pytest.fixture @@ -39,4 +39,4 @@ def redis_cluster_url() -> str: :return: URL string. """ - return os.environ.get("TEST_REDIS_CLUSTER_URL", "redis://localhost:7000") + return os.environ.get("TEST_REDIS_CLUSTER_URL", "redis://localhost:7001")