1.点击下载:yii2.0-redis扩展
2.把下载的扩展文件放到vendor/yiisoft/下,命名为yii2-redis
3.修改vender/yiisoft/下的extensions.php,加入redis扩展
‘yiisoft/yii2-redis‘ => array ( ‘name‘ => ‘yiisoft/yii2-redis‘, ‘version‘ => ‘2.2.0.0‘, ‘alias‘ => array ( ‘@yii/redis‘ => $vendorDir . ‘/yiisoft/yii2-redis‘, ), ),4.配置yii的component
‘redis‘ => [ ‘class‘ => ‘yii\redis\Connection‘, ‘hostname‘ => ‘localhost‘, ‘port‘ => 6379, ‘database‘ => 0, ],
5.这样我们的redis就配置完成了,接下来就是验证了
public function actionIndex() { Yii::$app->redis->set(‘test‘,‘111‘); //设置redis缓存 echo Yii::$app->redis->get(‘test‘); //读取redis缓存 exit; return $this->render(‘index‘); }
页面输出了“111”,就说明redis配置成功了
时间: 2024-10-29 19:08:07