Home  >  Article  >  Database  >  How to install Redis extension using YII2 framework

How to install Redis extension using YII2 framework

王林
王林forward
2023-05-26 18:41:411268browse

1.需要下载yii2-redis的master分支

windows版本composer下载

2.解压复制到vendor/yiisoft 下面

3.yiisoft下面extensions.php里面增加

'yiisoft/yii2-redis' =>
array (
'name' => 'yiisoft/yii2-redis',
'version' => '2.0.5.0',
'alias' =>
array (
'@yii/redis' => $vendorDir . '/yiisoft/yii2-redis',
),
),

4.在composer.json里面增加

How to install Redis extension using YII2 framework

"autoload": {
"psr-4":
"yii\\redis\\": "/yii2-redis/src/"
}
},

进入项目目录运行: composer dumpautoload

5.修改composer_psr4.php 找到'yii\\redis\\' 改为: 'yii\\redis\\' => array($vendorDir . '/yiisoft/yii2-redis/src'),

6.修改autoload_static.php 找到'yii\\redis\\' 改为 :'yii\\redis\\' =>array ( 0 => __DIR__ . '/..' . '/yiisoft/yii2-redis/src',),

7.web.php里面增加

'redis' =>[
'class' => 'yii\redis\Connection',
'hostname' => '127.0.0.1', #改为自己的redis服务器
'port' => 6379,
'database' => 0,
'connectionTimeout' => 5
],

可以使用Yii:$app->redis->set('foo','Hello');Yii:$app->redis->get('foo');进行测试下。

The above is the detailed content of How to install Redis extension using YII2 framework. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete