YII2
驱动支持类型:DB,redis,RabbitMQ , AMQP , Beanstalk , ActiveMQ and Gearman
手动引入:我这里的结构混乱无法使用composer引入,composer更简单 参考下面的官方文献即可
前置环境:yii2.0 php5.6 php-redis
下载压缩包:
https://github.com/yiisoft/yii2-redis
https://github.com/yiisoft/yii2-redis/archive/refs/tags/2.0.10.zip php5.6版本
https://github.com/yiisoft/yii2-queue
文献参考:
step1:
将文件解压到yii/yiisort下
/yii/composer/autoload_static.php增加
'yii\\redis\\' =>
array (
0 => __DIR__ . '/..' . '/yiisoft/yii2-redis/src',
),
queue同上
config/console.php & web.php新增配置
// === 1. Redis连接配置 ===
'redis' => [
'class' => 'yii\redis\Connection',
'hostname' => '127.0.0.1', // Redis地址(内网填实际地址)
'port' => 6379, // Redis端口
'database' => 0, // 数据库编号(避免与其他业务冲突)
//'timeout' => 0, // 连接超时(0=无限制)php5.6兼容版本无该属性
// 若Redis有密码,添加:
'password' => '',
],
// === 2. Queue核心配置 ===
'queue' => [
'class' => 'yii\queue\redis\Queue',
'redis' => 'redis', // 引用上面的Redis组件
'channel' => 'order_download_queue', // 业务通道名(自定义)
'ttr' => 3600, // 任务最大执行时间(秒,超时重试)
'attempts' => 3, // 失败重试次数
'timeout' => 0, // 消费者轮询超时(0=无限制)
// 可选:开启日志(便于排查问题)
'as log' => 'yii\queue\LogBehavior',
],