[1.x] feat: auto-detect phpredis, fall back to Predis#18
Merged
Conversation
If ext-redis is loaded, use phpredis as the driver. Otherwise fall back to Predis. No configuration change required by consumers. Documents persistent connections, Unix socket, and compression options in the README. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The cache subscriber hardcoded a Predis client check, causing it to immediately abort with "Expected Predis client" when phpredis (ext-redis) is the active driver. Route to a new `subscribePhpRedis()` method when the underlying client is a `\Redis` instance. phpredis `subscribe()` is blocking and callback-based rather than an iterator — set `OPT_READ_TIMEOUT = -1` for infinite timeout, and close the connection from within the callback to exit on `--once`. Predis path is unchanged. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
phpredis 6.x accepts a Closure as the second argument to subscribe() at runtime, but the PHPStan stubs incorrectly type it as array|string. Add @phpstan-ignore-next-line to suppress the false positive. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Without stubs, IDEs and PHPStan have no type information for \Redis (provided by ext-redis, not autoloaded via composer). The jetbrains stubs also carry the correct callable signature for Redis::subscribe(), so the @phpstan-ignore-next-line workaround is no longer needed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The larastan stubs (which CI resolves) still type subscribe()'s second argument as array|string, causing a false positive. The jetbrains stubs fix this locally but don't win the precedence race in CI. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ext-redis(phpredis) is installed, it is used as the Redis driver automatically. Otherwise Predis is used as a fallback.persistent,persistent_id), Unix socket connections, and compression options in the README.Why
Predis opens a new TCP connection per request. phpredis supports persistent connections, reusing the socket across requests within the same PHP-FPM worker. At scale this significantly reduces connection overhead and Valkey/Redis network bandwidth consumption.
Test plan
ext-redisloaded: driver resolves tophpredisext-redis: driver falls back topredispersistent: true+persistent_idhost: /path/to/redis.sock,port: 0🤖 Generated with Claude Code