Home > Database > Redis > body text

How to install Redis extension using YII2 framework

王林
Release: 2023-05-26 18:41:41
forward
1236 people have browsed it

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',
),
),
Copy after login

4.在composer.json里面增加

How to install Redis extension using YII2 framework

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

进入项目目录运行: 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
],
Copy after login

可以使用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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!