Download the PHP package veasin/ff-redis without Composer
On this page you can find all versions of the php package veasin/ff-redis. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download veasin/ff-redis
More information about veasin/ff-redis
Files in veasin/ff-redis
Package ff-redis
Short Description Redis connection pool, queue driver, and cache driver for ff framework
License LGPL-3.0-or-later
Homepage https://github.com/veasin/ff
Informations about the package ff-redis
ff-redis
Redis connection pool, queue driver, and cache driver for ff framework (PHP 8.4+).
Connection Pool
按配置名管理 Redis 连接生命周期,支持惰性验证与自动重连。由 ff\resource\redis() 函数实现,被 ff\cache\redis() 和 ff\queue\redis() 驱动内部自动调用,也可直接使用。
连接通过 container("#redis.{name}") 配置。默认 $name = 'default',未配置时自动回退:
Redis 扩展不存在或连接失败时返回 null,不会抛异常。
惰性验证
通过 #resource.redis.ttl 设置验证间隔(秒),超时后自动执行 ping() 检测连接健康,断连时自动重建。默认 0 不验证。
自定义工厂
Swoole 协程版 Redis 或其他自定义实现:
配置项
| 容器 key | 类型 | 说明 |
|---|---|---|
#redis.{name} |
array |
Redis 连接配置,支持 host、port、password、database、timeout、prefix |
#resource.redis.ttl |
int |
连接验证间隔秒数,默认 0 不验证 |
#resource/redis: |
callable |
自定义 Redis 工厂,签名 fn(array $config): \Redis |
Queue Driver
基于 Redis list 的队列驱动,生产使用 lPush + serialize,消费使用 brPop 阻塞弹出。
注册
ff-redis 的 bootstrap.php 已自动完成注册,安装后即可使用。
使用
独立使用
在 ext('queue', ...) 之外也可直接调用底层驱动:
timeout 为 brPop 阻塞等待秒数,0 表示永久阻塞。
配置
通过 container('#queue/redis') 配置:
| 容器 key | 类型 | 说明 |
|---|---|---|
#queue/redis |
array |
队列驱动配置:config、prefix、timeout、ttl |
Cache Driver
签名与 apcu() 完全一致。底层使用 ff\resource\redis() 获取连接,无需单独配置连接。
CRUD
中间件工厂模式
与 cache() 编排函数配合使用:
配置
| 容器 key | 类型 | 说明 |
|---|---|---|
#cache.redis |
array |
默认缓存 Redis 连接配置 |
#cache.redis.{name} |
array |
命名配置,支持 ttl、prefix |
Ext Registration
ff-redis 自动在 bootstrap.php 中注册 ext 驱动(通过 composer.json 的 autoload.files 加载):
安装后即可通过 ext('queue', 'redis', ...) 和 ext('cache', 'redis', ...) 调用。
也支持直接 use function ff\queue\redis / use function ff\cache\redis 独立使用。