安装yii2-redis
composer require yiisoft/yii2-redis
修改config/web.php 的 components 配置
'cache' => [ //'class' => 'yii\caching\FileCache', 'class' => 'yii\redis\Cache', ], 'redis' => [ 'class' => 'yii\redis\Connection', '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啦