owner888 / php-redis
Pure-PHP asynchronous Redis client (RESP2, Fiber connection pool, pipelines, transactions, Streams, Pub/Sub), powered by owner888/php-async.
v1.1.0
2026-11-30 21:51 UTC
Requires
- php: >=8.3
- owner888/php-async: ^1.0
Requires (Dev)
- phpunit/phpunit: ^11.0 || ^12.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Pure-PHP 8.3+ asynchronous Redis client powered by owner888/php-async.
- Non-blocking TCP and TLS (
rediss://) over Fibers — noext-redisC extension required. - Fiber-safe connection pool with backpressure (
Deferredwaiter queue) and idle expiry. - Binary-safe streaming RESP2 encoder/decoder.
- Pipelining,
MULTI/EXECtransactions, LuaEVAL, Streams (XREADGROUP BLOCKon dedicated connections), and Pub/Sub. - Shares the host's
Scheduler(such as Revolt/Workerman) automatically viaowner888/php-async, with no secondary event loop.
Installation
composer require owner888/php-redis
Quick Start
<?php use Owner888\Async\Async; use Owner888\Redis\RedisClient; Async::run(static function (): void { $redis = new RedisClient('redis://127.0.0.1:6379/0'); $redis->set('greeting', 'hello', ttlSeconds: 60); echo $redis->get('greeting'), "\n"; // Concurrent Fiber requests share the connection pool without blocking each other: $a = Async::spawn(static fn () => $redis->incr('hits')); $b = Async::spawn(static fn () => $redis->incr('hits')); echo $a->await(), ' / ', $b->await(), "\n"; $redis->close(); });
Streams (XREADGROUP BLOCK)
Blocking commands run on a dedicated connection so they never starve the shared pool:
$messages = $redis->xReadGroup( group: 'workers', consumer: 'worker-1', streams: ['stream:jobs' => '>'], count: 1, blockMs: 5000, );
Pipelines & Transactions
$replies = $redis->pipeline(static function ($pipe): void { $pipe->set('a', '1'); $pipe->incr('a'); $pipe->get('a'); });
Pub/Sub
$sub = $redis->subscriber(); $sub->subscribe('events'); $sub->listen(static function (string $channel, string $payload): bool { echo "[{$channel}] {$payload}\n"; return false; // return false to stop listening }); $sub->close();
Embedding in Workerman / Revolt
Install the host Scheduler once via Owner888\Async\Loop::useScheduler(...) (see php-async), then call RedisClient inside any worker Fiber.
Development
composer install
composer test
To also run the live Redis integration tests:
PHP_REDIS_TEST_HOST=127.0.0.1 PHP_REDIS_TEST_PORT=16379 composer test
License
MIT