mix / redis
Coroutine redis library based on Swoole, built-in connection pool
Installs: 9 217
Dependents: 13
Suggesters: 0
Security: 0
Stars: 6
Watchers: 2
Forks: 3
Open Issues: 0
Requires
- php: >=7.2.0
- ext-redis: *
- mix/object-pool: ~3.0.0
Requires (Dev)
- phpunit/phpunit: ^7.0.0
- dev-master
- v3.0.11
- v3.0.10
- v3.0.9
- v3.0.8
- v3.0.7
- v3.0.6
- v3.0.5
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v2.x-dev
- v2.2.16
- v2.2.14
- v2.2.12
- v2.2.9
- v2.2.7
- v2.2.5
- v2.2.2
- v2.2.1
- v2.1.x-dev
- v2.1.15.x-dev
- v2.1.15.1
- v2.1.15
- v2.1.2
- v2.1.1
- v2.1.0
- v2.1.0-RC2
- v2.1.0-RC
- v2.1.0-beta
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.1-RC5
- v2.0.1-RC
- v2.0.1-Beta2
This package is auto-updated.
Last update: 2024-11-04 11:58:07 UTC
README
OpenMix 出品:https://openmix.org
Mix Redis
PHP Redis for use in multiple execution environments, with support for FPM, CLI, Swoole, WorkerMan, and optional connection pool (coroutine)
可在各种环境中使用的 PHP Redis,支持 FPM、CLI、Swoole、WorkerMan,可选的连接池 (协程)
技术交流
知乎:https://www.zhihu.com/people/onanying
官方QQ群:284806582
, 825122875
敲门暗号:redis
Installation
composer require mix/redis
Quick start
$rds = new Mix\Redis\Redis('127.0.0.1', 6379, 'password', 0); $rds->set('foo', 'bar'); $value = $rds->get('foo');
Start Pool
在 Swoole
协程环境中,启动连接池
$maxOpen = 50; // 最大开启连接数 $maxIdle = 20; // 最大闲置连接数 $maxLifetime = 3600; // 连接的最长生命周期 $waitTimeout = 0.0; // 从池获取连接等待的时间, 0为一直等待 $rds->startPool($maxOpen, $maxIdle, $maxLifetime, $waitTimeout); Swoole\Runtime::enableCoroutine(); // 必须放到最后,防止触发协程调度导致异常
连接池统计
$rds->poolStats(); // array, fields: total, idle, active
Transaction Multi & Pipeline
Multi
事务块内的多条命令会按照先后顺序被放进一个队列当中,最后由exec命令原子性(atomic)地执行。
$tx = $rds->multi(); $tx->set('foo', 'bar'); $tx->set('foo1', 'bar1'); $ret = $tx->exec();
Pipeline
客户端将执行的命令写入到缓冲中,最后由exec命令一次性发送给redis执行返回。
$tx = $rds->pipeline(); $tx->set('foo', 'bar'); $tx->set('foo1', 'bar1'); $ret = $tx->exec();
Transaction Watch
监听值的变化,如果执行时有变化则事务失败,无变化则事务成功。
$tx = $rds->watch('foo'); $tx->incr('foo'); $ret = $tx->exec();
Logger
日志记录器,配置后可打印全部SQL信息
$db->setLogger($logger);
$logger
需实现 Mix\Redis\LoggerInterface
interface LoggerInterface { public function trace(float $time, string $cmd, array $args, ?\Throwable $exception): void; }
License
Apache License Version 2.0, http://www.apache.org/licenses/