在YII2中使用redis

一、安装YII2的redis扩展

composer require --prefer-dist yiisoft/yii2-redis

二、 配置basic/config/web.php

在components数组中添加如下内容:

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

三、 使用

$redis = Yii::$app->redis;
$redis->set('k','v');
$redis->get('k');
posted @ 2016-09-26 14:30  宋子庆  阅读(1984)  评论(0编辑  收藏  举报