Visitar URL original
Expose renewSlotCache on JedisCluster as public API by agarwalbharat · Pull Request #4555 · redis/jedis · GitHub
Skip to content

Expose renewSlotCache on JedisCluster as public API - #4555

Merged
ggivo merged 1 commit into
redis:masterfrom
agarwalbharat:feature/jediscluster-public-renew-slot-cache
Jun 3, 2026
Merged

ggivo merged 1 commit into
redis:masterfrom
agarwalbharat:feature/jediscluster-public-renew-slot-cache

Conversation

@agarwalbharat

@agarwalbharat agarwalbharat commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Jedis already supports refreshing the Redis Cluster slot cache internally through ClusterConnectionProvider.renewSlotCache(), but callers directly using do not have a public API to trigger that refresh directly.

This is useful for applications that detect stale or incomplete cluster topology state outside the normal command retry path, especially for direct slot/node workflows such as getConnectionFromSlot().

Add JedisCluster#refreshClusterTopology() as a public API that delegates to the existing ClusterConnectionProvider renewal path.
This gives applications an explicit way to refresh the in-memory cluster slot cache when they detect stale topology state outside the normal command retry flow.

Closes : #4154


Note

Low Risk
Thin public wrapper over existing renewal logic; no new topology algorithm, only broader caller access to a path already used internally.

Overview
Adds refreshClusterTopology() on JedisCluster and RedisClusterClient, exposing a way for apps to force an in-memory cluster topology refresh (nodes and slot map) by delegating to the existing ClusterConnectionProvider#renewSlotCache() path—intended when stale routing is noticed outside normal command retries, e.g. before getConnectionFromSlot(int).

Unit tests assert both clients call renewSlotCache() on the provider (mocked JedisCluster constructor and RedisClusterClient builder).

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

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit ac634ee. Configure here.

@ggivo

ggivo commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Thanks @agarwalbharat - One naming change before merge.

Rename the public renewSlotCache() → refreshClusterTopology().

It refreshes the full topology (nodes + primary/replica slots), not just a slot cache, and it matches the existing TopologyRefresh* naming already in the codebase. Since this is a permanent public API, worth getting the name right.

/**
 * Forces an immediate refresh of the in-memory Redis Cluster topology
 * (node map, primary and replica slot assignments).
 * <p>
 * Useful before {@link #getConnectionFromSlot(int)} when stale topology is
 * detected outside the command retry path. Best-effort; a no-op if a refresh
 * is already in progress.
 */
public void refreshClusterTopology() {
  ((ClusterConnectionProvider) provider).renewSlotCache();
}

Same on both JedisCluster and RedisClusterClient;

Thanks again!

Add JedisCluster#refreshClusterTopology() as a public API that delegates to the existing ClusterConnectionProvider renewal path. This gives applications an explicit way to refresh the in-memory cluster slot cache when they detect stale topology state outside the normal command retry flow.
@agarwalbharat
agarwalbharat force-pushed the feature/jediscluster-public-renew-slot-cache branch from 80bfbf4 to 1bcab78 Compare June 3, 2026 07:21
@agarwalbharat

Copy link
Copy Markdown
Contributor Author

Thank you @ggivo for the review.
I have updated function as per suggestion.

@ggivo ggivo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ggivo ggivo added this to the 8.0.0 milestone Jun 3, 2026
@ggivo
ggivo merged commit e6444fb into redis:master Jun 3, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Best way to "renewSlotCache" in JedisCluster?

2 participants