Yii2-redis安装配置

编辑composer.json文件

vim composer.json
加入"yiisoft/yii2-redis": "~2.0.0"

执行更新

composer update

配置Yii的component

'redis' => [
        'class' => 'yii\redis\Connection',
        'hostname' => 'localhost',
        'port' => 6379,
        'database' => 0,
],

验证

public function actionTest()
{   
    Yii::$app->redis->set('test','hello yii2-reids');  //设置redis缓存
    echo Yii::$app->redis->get('test');   //读取redis缓存
    exit;
    return $this->render('test');
}

页面输出

posted @ 2017-04-20 21:58  selfim  阅读(2544)  评论(0编辑  收藏  举报