| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Adds a 'hosts' array option to RedisSentinel::__construct so the client
transparently falls back to the next Sentinel endpoint on network failure,
eliminating the need for userland workarounds in HA deployments.
$sentinel = new RedisSentinel(['hosts' => [
['host' => '10.0.0.1', 'port' => 26379],
['host' => '10.0.0.2', 'port' => 26379],
['host' => '10.0.0.3', 'port' => 26379],
]]);
Semantics:
- Sticky connection: the first reachable host is used until it fails.
- One command-level retry per call; a bounded linear scan inside
sentinel_try_next_host iterates remaining hosts on a failed attempt.
- Skipped hosts are not revisited for the instance lifetime.
- Network error detection inspects RedisSock state (status, stream),
not exception message strings.
- Zero BC risk: when 'hosts' is absent, behavior is identical to today.
Host list is stored on RedisSock as three new fields; sentinel_host_entry
is forward-declared in common.h with the full struct in sentinel_library.h
so redis_object / Redis / RedisCluster layouts are untouched.
All 11 RedisSentinel methods wrap their REDIS_PROCESS_KW_CMD call in a
new SENTINEL_METHOD macro that implements the retry. No-op on single-host.
Refs phpredis#2819
- Stub phpdoc on __construct describes the 'hosts' option alongside the existing single-host parameters. - sentinel.md gains a 'Multi-host support' section covering API, semantics (sticky, bounded retry, no rehydration), and error handling (RedisException on validation and exhaustion). - Regenerated arginfo reflects only the new stub hash; method signatures are unchanged. Refs phpredis#2819
Adds 17 integration tests (tests/RedisSentinelMultiHostTest.php) covering: - Construction with 'hosts' array - Connect-time fallback through dead hosts - Exhaustion throwing RedisException with host count in message - Validation errors (empty, missing 'host' key, wrong types, oversized) - DoS guard (>1024 hosts rejected) - Default port (26379) when omitted - Single-host BC path unchanged - Auth propagation (skipped unless SENTINEL_AUTH_PASS is set) - Sticky behavior verified via call-time comparison - Bounded retry elapsed-time check Tests mark themselves skipped when the local Sentinel env isn't reachable, so existing local test runs are unaffected. The env itself (tests/sentinel-multihost/) is a minimal docker-compose cluster with 1 master + 2 replicas + 3 Sentinels on ports 26379/80/81. Refs phpredis#2819
Runs the RedisSentinelMultiHostTest integration tests across PHP 8.1-8.4 against the docker-compose cluster in tests/sentinel-multihost/. - docker compose up, wait for Sentinels via 'nc -z' - phpize + configure --enable-redis + make - php tests/TestRedis.php --class redissentinelmultihost - Dumps docker logs on failure for triage - Tears down the cluster in all outcomes Refs phpredis#2819
| Back | FazBrowse Home | New Git URL |
Summary
Adds native multi-host support to RedisSentinel via a new hosts constructor option, eliminating the need for userland workarounds such as namoshek/laravel-redis-sentinel for the Sentinel discovery portion of the problem.
Partially addresses #2819. Related prior discussion: #2132.
API
Semantics
Not in this PR (deferred)
To keep scope reviewable, the following are deferred to a follow-up:
The supporting infrastructure introduced here (RedisSock->sentinel_hosts, sentinel_try_next_host) is reusable for that follow-up.
Implementation notes
Testing
Open questions
Happy to adjust any of these based on maintainer preference:
Opened as Draft to invite design discussion before marking ready for review.