Visitar URL original
Fix 'MultiDbClient' compatibility with client-side cache-enabled configuration by atakavci · Pull Request #4568 · redis/jedis · GitHub
Skip to content

Fix 'MultiDbClient' compatibility with client-side cache-enabled configuration - #4568

Merged
atakavci merged 12 commits into
redis:masterfrom
atakavci:ali/multidbwithcache
Jul 2, 2026
Merged

atakavci merged 12 commits into
redis:masterfrom
atakavci:ali/multidbwithcache

Conversation

@atakavci

@atakavci atakavci commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR fixes client-side caching support with MultiDbConnectionProvider by threading the Cache instance through the connection provider and pool layers.

Changes

Core Implementation

  • MultiDbConnectionProvider: Added new constructor accepting Cache parameter and updated pool creation to pass cache to TrackingConnectionPool
  • TrackingConnectionPool: Extended builder pattern to accept and propagate Cache through connection factory and pool recreation
  • MultiDbClientBuilder: Updated to pass cache instance when constructing MultiDbConnectionProvider

Key Features

  • Cache instance is shared across all database connections in a multi-database setup
  • Cache is preserved during database switches and pool recreations
  • Backward compatibility maintained with no-arg constructor for non-cached scenarios

Testing

Added comprehensive test coverage including:

  • Basic cache functionality with MultiDbClient
  • Cache preservation during pool recreation (fast failover scenario)
  • Cache behavior with dynamic database additions
  • Cache persistence across database switches

Test Improvements

  • Disabled health checks in most tests for faster execution
  • Updated test assertions to work with health check disabled mode
  • Added proper health check configuration for tests that need it

Files Changed

  • MultiDbConnectionProvider.java - Added cache support with dual constructors
  • TrackingConnectionPool.java - Enhanced builder to accept and propagate cache
  • MultiDbClientBuilder.java - Updated provider instantiation to include cache
  • MultiDbClientTest.java - Added 4 new cache-related tests and improved existing tests

Note

Medium Risk
Changes affect multi-database connection pooling and cache invalidation on failover/switch; incorrect cache sharing could serve stale data across endpoints, though behavior is heavily tested.

Overview
MultiDbClient can now use client-side caching (CSC) by passing the builder’s Cache into MultiDbConnectionProvider, through TrackingConnectionPool / ConnectionFactory, so pooled connections become CacheConnection when a cache is configured. The same cache instance is reused when pools are rebuilt via TrackingConnectionPool.from() (e.g. after fast failover closes the old pool).

MultiDbClientBuilder constructs the provider with cache; the original single-arg provider constructor remains for non-cached setups.

Tests add RESP2/RESP3 parameterization for MultiDbClientTest, CSC integration scenarios (switches, dynamic DB add, pool recreation), RedisMultiDbClientSideCacheTest, mock-server MultiDbCSCTest (flush on fast-failover switch vs no flush otherwise), and coverage for mid-transaction active-database switches on MultiDbTransaction.

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes client-side caching (CSC) for MultiDbClient by propagating a shared Cache instance from MultiDbClientBuilder into MultiDbConnectionProvider, then down into TrackingConnectionPool so cache-enabled connections continue to work across database switches and pool recreation.

Changes:

  • Thread Cache from MultiDbClientBuilder → MultiDbConnectionProvider → TrackingConnectionPool/ConnectionFactory (and preserve it on TrackingConnectionPool.from() pool recreation).
  • Add cache-focused integration tests for multi-db CSC behavior (including fast-failover/pool recreation and dynamic database addition).
  • Speed up existing integration tests by disabling health checks for most scenarios.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/main/java/redis/clients/jedis/mcf/MultiDbConnectionProvider.java Adds cache-aware constructor and passes Cache into pool creation.
src/main/java/redis/clients/jedis/mcf/TrackingConnectionPool.java Extends builder to accept Cache and ensures recreated pools keep the same cache.
src/main/java/redis/clients/jedis/builders/MultiDbClientBuilder.java Passes builder cache into MultiDbConnectionProvider.
src/test/java/redis/clients/jedis/MultiDbClientTest.java Adds CSC integration coverage and updates tests to avoid health-check waits in most cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@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 using default effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 6fc5518. Configure here.


// Create the multi-database connection provider
MultiDbConnectionProvider provider = new MultiDbConnectionProvider(multiDbConfig);
MultiDbConnectionProvider provider = new MultiDbConnectionProvider(multiDbConfig, cache);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Custom provider hides client cache

Medium Severity

If MultiDbClient is built with a preconfigured MultiDbConnectionProvider that was constructed with a Cache, connections use client-side caching but UnifiedJedis.getCache() stays null unless the same Cache is also passed on the builder.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 6fc5518. Configure here.

@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

@atakavci
atakavci merged commit 4ac22d5 into redis:master Jul 2, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants