RedisProxy
class RedisProxy implements Connection mixin RedisConnection
Pool-aware Redis connection proxy.
Each proxy represents a named Redis connection. Commands are executed by checking out a connection from the pool, running the command, and releasing the connection back. Context management ensures that stateful commands reuse the same connection within a coroutine.
Traits
Coroutine multi-exec trait.
Constants
| private CONNECTION_BOUND_METHODS |
Methods that must be called while explicitly holding a pool connection. These methods must remain excluded from Redis facade generation. |
Methods
Execute commands in a pipeline.
Execute commands in a transaction.
Create a new Redis proxy instance.
Get the connection name.
Determine if this connection uses Redis Cluster.
Register a custom Redis connection macro.
Mix another object into the Redis connection.
Determine if a Redis connection macro is registered.
Flush the registered Redis connection macros.
Scan keys matching a pattern.
Scan hash fields matching a pattern.
Scan sorted set members matching a pattern.
Scan set members matching a pattern.
Pass dynamic method calls to a pooled Redis connection.
Release the connection stored in coroutine context.
Discard the connection stored in coroutine context.
Handle subscribe/psubscribe using the coroutine-native subscriber.
Determine which commands must reuse the same connection.
Get a connection from coroutine context, or from redis connection pool.
The key to identify the connection object in coroutine context.
Execute callback with a pinned connection from the pool.
Pin a pool connection in coroutine context for the duration of a callback.
Execute a callback with serialization and compression temporarily disabled.
Create a coroutine-native Redis subscriber.
Subscribe to a set of given channels with wildcards.
Run a command against the Redis database.
Throttle a callback for a maximum number of executions over a given duration.
Funnel a callback for a maximum number of simultaneous executions.
Flush (delete) all Redis keys matching a pattern.
No description
Details
in
MultiExec at line 24
Redis : array<int, mixed>|false)
pipeline(callable|null $callback = null)
Execute commands in a pipeline.
in
MultiExec at line 34
Redis|RedisCluster : array<int, mixed>|false)
transaction(callable|null $callback = null)
Execute commands in a transaction.
at line 91
__construct(PoolManager $poolManager, string $poolName, RedisSentinelFactory $sentinelFactory)
Create a new Redis proxy instance.
at line 101
string
getName()
Get the connection name.
at line 109
bool
isCluster()
Determine if this connection uses Redis Cluster.
at line 121
void
macro(string $name, callable|object $macro)
Register a custom Redis connection macro.
Macros persist for the worker lifetime and affect every Redis connection.
at line 132
void
mixin(object $mixin, bool $replace = true)
Mix another object into the Redis connection.
Registered macros persist for the worker lifetime and affect every Redis connection.
at line 141
bool
hasMacro(string $name)
Determine if a Redis connection macro is registered.
at line 151
void
flushMacros()
Flush the registered Redis connection macros.
Concurrent coroutines may resolve different methods during a flush.
at line 160
mixed
scan(mixed $cursor, mixed ...$arguments)
Scan keys matching a pattern.
at line 168
mixed
hScan(mixed $key, mixed $cursor, mixed ...$arguments)
Scan hash fields matching a pattern.
at line 176
mixed
zScan(mixed $key, mixed $cursor, mixed ...$arguments)
Scan sorted set members matching a pattern.
at line 184
mixed
sScan(mixed $key, mixed $cursor, mixed ...$arguments)
Scan set members matching a pattern.
at line 192
mixed
__call(string $name, array $arguments)
Pass dynamic method calls to a pooled Redis connection.
at line 354
void
releaseContextConnection()
| internal |
Release the connection stored in coroutine context.
at line 371
void
discardContextConnection()
| internal |
Discard the connection stored in coroutine context.
at line 389
protected void
handleSubscribe(string $name, array $arguments)
Handle subscribe/psubscribe using the coroutine-native subscriber.
Creates a dedicated socket connection (not from the pool) and bridges the channel-based subscriber to the Laravel-style callback API.
at line 442
protected bool
shouldUseSameConnection(string $methodName)
Determine which commands must reuse the same connection.
at line 458
protected RedisConnection
getConnection(bool $hasContextConnection, bool $transform = true)
Get a connection from coroutine context, or from redis connection pool.
at line 477
protected string
getContextKey()
The key to identify the connection object in coroutine context.
at line 505
mixed
withConnection(callable $callback, bool $transform = true)
Execute callback with a pinned connection from the pool.
Use this for operations requiring multiple commands on the same connection (e.g., evalSha + getLastError, multi-step Lua operations). The connection is automatically returned to the pool after the callback completes.
If a connection is already stored in coroutine context (e.g., from an active multi/pipeline), that connection is reused and not released.
at line 548
mixed
withPinnedConnection(callable $callback)
Pin a pool connection in coroutine context for the duration of a callback.
All Redis operations inside the callback will reuse the same connection, avoiding multiple pool checkouts. Re-entrant: if a connection is already pinned, the callback runs on it without re-pinning.
at line 601
mixed
withoutSerializationOrCompression(callable $callback)
Execute a callback with serialization and compression temporarily disabled.
Pins a pool connection and disables phpredis serialization and compression for the duration of the callback, then restores settings and releases.
This is needed for rate limiter counters which must be stored as raw integers — phpredis serialization (e.g., igbinary) would corrupt them.
at line 622
Subscriber
subscriber()
Create a coroutine-native Redis subscriber.
Returns a Subscriber with its own dedicated socket connection (not from the pool). Use for the channel-based pub/sub API:
$sub = Redis::subscriber();
$sub->subscribe('channel');
while ($message = $sub->channel()->pop()) { ... }
$sub->close();
at line 776
void
listen(Closure $callback)
Register a Redis command listener with the connection.
The listener persists on the singleton event dispatcher for the worker lifetime and runs for every subsequent Redis command event.
at line 792
void
listenForFailures(Closure $callback)
Register a Redis command failure listener with the connection.
The listener persists on the singleton event dispatcher for the worker lifetime and runs for every subsequent Redis failure event.
at line 805
void
subscribe(array|string $channels, Closure $callback)
Subscribe to a set of given channels for messages.
at line 813
void
psubscribe(array|string $channels, Closure $callback)
Subscribe to a set of given channels with wildcards.
at line 823
mixed
command(string $method, array $parameters = [])
Run a command against the Redis database.
at line 831
DurationLimiterBuilder
throttle(string $name)
Throttle a callback for a maximum number of executions over a given duration.
at line 839
ConcurrencyLimiterBuilder
funnel(string $name)
Funnel a callback for a maximum number of simultaneous executions.
at line 864
int
flushByPattern(string $pattern)
Flush (delete) all Redis keys matching a pattern.
Use this for standalone/one-off flush operations. It handles the connection lifecycle automatically (get from pool, flush, release). Uses the default connection, or specify one via Redis::connection($name)->flushByPattern().
If you already have a raw connection from withConnection(..., transform: false), call $connection->flushByPattern() directly to avoid redundant pool operations.
Uses SCAN to iterate keys efficiently and deletes them in batches. Correctly handles OPT_PREFIX to avoid the double-prefixing bug.
at line 41
Redis
discard()
No description