Skip to content

Handle ASK redirects to uncached cluster nodes#4070

Open
Sean-Kenneth-Doherty wants to merge 1 commit into
redis:masterfrom
Sean-Kenneth-Doherty:fix-ask-redirect-uncached-node
Open

Handle ASK redirects to uncached cluster nodes#4070
Sean-Kenneth-Doherty wants to merge 1 commit into
redis:masterfrom
Sean-Kenneth-Doherty:fix-ask-redirect-uncached-node

Conversation

@Sean-Kenneth-Doherty

@Sean-Kenneth-Doherty Sean-Kenneth-Doherty commented May 16, 2026

Copy link
Copy Markdown

Summary

  • add a node-cache helper for ASK redirect targets that are missing from the current topology
  • use that helper in sync and asyncio cluster ASK handling before issuing ASKING
  • add sync and asyncio regressions for ASK redirects to uncached zero-slot nodes

Fixes #4015.

Validation

  • TMPDIR=$PWD/.tmp PIP_CACHE_DIR=$PWD/.tmp/pip-cache uv run --with-requirements dev_requirements.txt pytest tests/test_cluster.py::TestRedisClusterObj::test_ask_redirection_to_uncached_node tests/test_asyncio/test_cluster.py::TestRedisClusterObj::test_ask_redirection_to_uncached_node -q
  • TMPDIR=$PWD/.tmp PIP_CACHE_DIR=$PWD/.tmp/pip-cache uv run --with-requirements dev_requirements.txt ruff check redis/cluster.py redis/asyncio/cluster.py tests/test_cluster.py tests/test_asyncio/test_cluster.py
  • TMPDIR=$PWD/.tmp PIP_CACHE_DIR=$PWD/.tmp/pip-cache uv run --with-requirements dev_requirements.txt ruff format --check redis/cluster.py redis/asyncio/cluster.py tests/test_cluster.py tests/test_asyncio/test_cluster.py
  • git diff --check origin/master...HEAD

Note: broader cluster-object test classes require the repository's Docker-backed Redis Cluster dev environment and were not usable as local proof here; the new regressions are mocked and passed locally.

Assisted-by: OpenAI Codex


Note

Medium Risk
Changes cluster redirection behavior by creating/caching nodes on-the-fly during ASK handling in both sync and asyncio clients, which can affect routing and node cache consistency under topology edge cases.

Overview
Fixes ASK redirection when the target node is not present in the current cluster topology by introducing NodesManager.get_or_create_node() and using it in both sync (redis/cluster.py) and asyncio (redis/asyncio/cluster.py) AskError handling before issuing ASKING.

Adds sync and asyncio regression tests that simulate an ASK redirect to an uncached (zero-slot) node and assert the node is cached as a PRIMARY and the redirected command succeeds.

Reviewed by Cursor Bugbot for commit 984e2eb. Bugbot is set up for automated code reviews on this repo. Configure here.

@jit-ci

jit-ci Bot commented May 16, 2026

Copy link
Copy Markdown

Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset.

In case there are security findings, they will be communicated to you as a comment inside the PR.

Hope you’ll enjoy using Jit.

Questions? Comments? Want to learn more? Get in touch with us.

@Sean-Kenneth-Doherty Sean-Kenneth-Doherty marked this pull request as ready for review May 16, 2026 23:24
@Sean-Kenneth-Doherty Sean-Kenneth-Doherty force-pushed the fix-ask-redirect-uncached-node branch from 15fc46e to 984e2eb Compare May 16, 2026 23:26
@Sean-Kenneth-Doherty

Copy link
Copy Markdown
Author

Fresh local validation on the current branch:

  • TMPDIR=$PWD/.tmp PIP_CACHE_DIR=$PWD/.tmp/pip-cache uv run --with-requirements dev_requirements.txt pytest tests/test_cluster.py::TestRedisClusterObj::test_ask_redirection_to_uncached_node tests/test_asyncio/test_cluster.py::TestRedisClusterObj::test_ask_redirection_to_uncached_node -q -> 2 passed with one pytest config warning about the existing capture option
  • TMPDIR=$PWD/.tmp PIP_CACHE_DIR=$PWD/.tmp/pip-cache uv run --with-requirements dev_requirements.txt ruff check redis/cluster.py redis/asyncio/cluster.py tests/test_cluster.py tests/test_asyncio/test_cluster.py -> clean
  • TMPDIR=$PWD/.tmp PIP_CACHE_DIR=$PWD/.tmp/pip-cache uv run --with-requirements dev_requirements.txt ruff format --check redis/cluster.py redis/asyncio/cluster.py tests/test_cluster.py tests/test_asyncio/test_cluster.py -> clean
  • git diff --check origin/master...HEAD -> clean

I removed the temporary .tmp and generated uv.lock artifacts afterward; the local branch is clean. Broader cluster-object coverage still needs the Docker-backed Redis Cluster dev environment, so the local proof here is the mocked sync/async regression this PR adds.

@petyaslavova

Copy link
Copy Markdown
Collaborator

Hi @Sean-Kenneth-Doherty thank you for your contribution! I will have a look at it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resharding redis cluster

2 participants