1. 输入命令:php composer.phar require --prefer-dist yiisoft/yii2-redis
如果报错 “Could not open input file: composer.phar” 则重新输入命令:composer require --prefer-dist yiisoft/yii2-redis
2. 完成后,在配置文件web.php中添加相应配置:
'redis' => [
'class' => 'yii\redis\Connection',
'hostname' => 'localhost',
'port' => 6379,
'database' => 0,
],
3. 在控制器中进行测试:
$redis = Yii::$app->redis;
$redis->set('key','hello world!');
$result = $redis->get('key');
var_dump($result);
【版权申明】未经博主同意,谢绝转载!(请尊重原创,博主保留追究权) http://www.cnblogs.com/facetwitter/p/6029664.html