Skip to content

feat(redis): Redis Sentinel high-availability support (v2.0) - #15

Merged
wezell merged 2 commits into
trunkfrom
feature-redis-sentinel-support
May 30, 2026
Merged

wezell merged 2 commits into
trunkfrom
feature-redis-sentinel-support

Conversation

@wezell

@wezell wezell commented May 30, 2026

Copy link
Copy Markdown
Member

Summary

Makes Redis Sentinel actually work. Before this, sentinelMaster/sentinels were parsed, exposed via getters, and printed in the startup banner — but initializeRedisConnection() always built a direct JedisPooled to host:port. A deployment that configured Sentinel for HA silently got no failover.

Now, when both TOMCAT_REDIS_SESSION_SENTINEL_MASTER and TOMCAT_REDIS_SESSION_SENTINELS are set, the manager connects through JedisSentineled, which discovers the current master from the sentinel nodes and fails over automatically when the master changes.

jedisPool = isSentinelConfigured()
    ? buildSentinelConnection()    // JedisSentineled(master, masterCfg, poolCfg, sentinels, sentinelCfg)
    : buildStandaloneConnection(); // JedisPooled (unchanged)

Details

  • Sentinel detection requires both a master name and a non-empty sentinel list; otherwise it falls back to the existing direct connection (no behavioral change for non-Sentinel users).
  • Master connection inherits the configured username, password, database, SSL, and timeout (via DefaultJedisClientConfig).
  • Sentinel nodes are queried with timeout + SSL only — Sentinels typically have their own (or no) auth and don't expose application databases.
  • Reuses the existing ConnectionPoolConfig (which extends GenericObjectPoolConfig<Connection>) for the master pool.
  • Connection construction split into isSentinelConfigured() / buildSentinelConnection() / buildStandaloneConnection().
  • README documents the two env vars (previously only shown in the XML example).

Bumps version 1.8 → 2.0 (Sentinel is a significant new capability).

Verification

Compiles against the real Jedis 4.4.6 API (constructor/builder signatures verified against the jar). Runtime failover was not exercised — that needs a live Sentinel cluster (1 master + replicas + ≥1 sentinel). Reviewers with a Sentinel environment should smoke-test master discovery and a failover.

🤖 Generated with Claude Code

Previously sentinelMaster/sentinels were parsed, exposed, and logged but
never used -- initializeRedisConnection() always built a direct JedisPooled
to host:port, so a Sentinel deployment got no failover (silent).

Now, when both TOMCAT_REDIS_SESSION_SENTINEL_MASTER and
TOMCAT_REDIS_SESSION_SENTINELS are set, the manager connects via
JedisSentineled: it discovers the current master through the sentinels and
fails over automatically. The master connection inherits username, password,
database, SSL, and timeout; sentinel nodes are queried with timeout/SSL only.
Without sentinel config, behavior is unchanged (direct JedisPooled).

Connection construction is split into isSentinelConfigured() /
buildSentinelConnection() / buildStandaloneConnection() for clarity.
Documents the two env vars in the README. Bumps version 1.8 -> 2.0.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… standalone)

setSentinels("") (e.g. an empty context.xml Manager attribute) yields a
HashSet containing a single empty string, which is non-empty as a set, so
isSentinelConfigured() returned true and the connection path handed
JedisSentineled an empty sentinel set -- failing instead of falling back to
the documented standalone connection. Require at least one non-blank entry.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Codex Autonomous Review:

  • Overall: patch is correct
  • New findings this run: 0
  • Prior unresolved Codex findings still relevant: 0
  • Active findings total: 0

The incremental change fixes the previously reported blank-sentinel edge case by requiring at least one non-blank sentinel entry before enabling Sentinel mode. I did not find any new bugs introduced by this update.

Tip: comment with "/codex address comments" to attempt automated fixes for unresolved review threads.

@wezell
wezell merged commit 27772e8 into trunk May 30, 2026
1 check passed
@wezell
wezell deleted the feature-redis-sentinel-support branch May 30, 2026 03:43
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.

1 participant