1 安装redis
https://blog.csdn.net/gaotanpan3666/article/details/83047081 安装redis
2 yii安装redis扩展
composer require --prefer-dist yiisoft/yii2-redis
3配置basic/config/web.php
在components数组中添加如下内容:
'redis' => [ 'class' => 'yii edisConnection', 'hostname' => 'localhost', 'port' => 6379, 'database' => 0, ],
4 使用
$redis = Yii::$app->redis; $redis->set('k','v'); $redis->get('k');