安装yii2-redis
composer require yiisoft/yii2-redis
修改config/web.php 的 components 配置
'cache' => [ //'class' => 'yiicachingFileCache', 'class' => 'yii edisCache', ], 'redis' => [ 'class' => 'yii edisConnection', 'hostname' => '127.0.0.1', 'port' => 6668, 'password' => 123456, 'database' => 0, ],
栗子:
控制器里
public function actionTestredis() { Yii::$app->redis->set('test','111'); }
参考资料: https://www.yiiframework.com/doc/guide/2.0/zh-cn/yii2-redis OK啦