Download the PHP package phpdot/redis without Composer
On this page you can find all versions of the php package phpdot/redis. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package redis
Short Description Coroutine-safe Redis client wrapping ext-redis with auto-reconnect, exponential backoff, exception translation, and a pool connector for phpdot/pool.
License MIT
Informations about the package redis
phpdot/redis
Coroutine-safe Redis client for PHP 8.4+. Wraps ext-redis \Redis with auto-reconnect, exponential backoff, exception translation, and a pool connector for phpdot/pool.
One RedisConnection owns one \Redis socket. Under Swoole, borrow a connection per coroutine through a pool so no two coroutines ever interleave commands on one socket — the same pattern phpdot/mongodb uses.
Table of Contents
- Install
- Quick Start
- Architecture
- RedisConnection
- RedisConfig
- Lifecycle
- Resilience
- Coroutine Safety
- Connection Pooling
- Exception Handling
- Escape Hatch
- API Reference
Install
Requires PHP 8.4+, ext-redis ^6.0, and phpdot/contracts ^1.4.
Quick Start
Architecture
RedisConfig— immutable connection parameters (#[Config('redis')]).RedisConnection— lifecycle + the raw\Redisseam. Mirrorsphpdot/mongodb'sMongoConnection.RedisConnector— adaptsRedisConnectionto the pool contract. MirrorsMongoConnector. Depends only onphpdot/contracts, so the package works withoutphpdot/pool(FPM, CLI, scripts).
RedisConnection
RedisConfig
Lifecycle
Resilience
connect() retries up to maxRetries times with exponential backoff (100ms → 200ms → 400ms…). AUTH failures (NOAUTH, WRONGPASS) throw AuthenticationException immediately and are not retried. All other connection failures accumulate and throw ConnectionException once the retry budget is exhausted.
Coroutine Safety
ext-redis commands are blocking socket I/O. Two coroutines sharing one \Redis interleave request/reply bytes and corrupt each other — this is the footgun phpdot/redis-ql's own docs warn about.
phpdot/redis makes the safe pattern trivial: pool connections, borrow one per coroutine. Each pooled RedisConnection wraps exactly one \Redis; a coroutine borrows it, runs commands via getClient(), and returns it. No socket is ever shared across concurrent coroutines.
Connection Pooling
RedisConnector implements PHPdot\Contracts\Pool\ConnectorInterface, so phpdot/pool can hold and manage RedisConnection instances:
The connector depends only on phpdot/contracts — phpdot/pool is not a runtime requirement, so the package stays usable in non-pooled runtimes (FPM, CLI one-shots).
Exception Handling
RedisException from ext-redis is caught and translated inside connect(); RedisConnection's own methods throw PHPdot\Redis\Exception\* types only.
Escape Hatch
getClient(): \Redis returns the underlying ext-redis instance for any command the wrapper does not surface. This is the primary consumer seam — phpdot/cache's RedisDriver, phpdot/session's RedisHandler, and phpdot/redis-ql's PhpRedisClient can all receive a pooled \Redis through it.
API Reference
RedisConfig API
| Method | Returns | Notes |
|---|---|---|
connectHost() |
string |
socket path or tls://-prefixed host |
buildContext() |
?array |
merged stream/SSL context, or null |
getHostString() |
string |
socket path or host:port for errors |
RedisConnection API
| Method | Returns | Throws |
|---|---|---|
connect() |
void |
ConnectionException, AuthenticationException |
close() |
void |
never |
isConnected() |
bool |
never |
ping() |
bool |
never |
ensureConnected() |
void |
ConnectionException |
reconnect() |
void |
ConnectionException, AuthenticationException |
getClient() |
\Redis |
ConnectionException |
getConfig() |
RedisConfig |
never |
RedisConnector API
Implements PHPdot\Contracts\Pool\ConnectorInterface.
| Method | Returns | Notes |
|---|---|---|
connect() |
object |
fresh connected RedisConnection |
isAlive(object) |
bool |
type-guarded + ping() |
close(object) |
void |
type-guarded, never throws |