Home > Backend Development > PHP Tutorial > Yii2 里使用Redis扩展

Yii2 里使用Redis扩展

WBOY
Release: 2016-06-23 13:01:33
Original
1061 people have browsed it

Redis是个很不错的Nosql数据库,比Memcached的好处是能持久化数据。Yii2里使用Redis ,首先要扩展Redis。可以在composer.json 里添加 redis

"require": {        "php": ">=5.4.0",        "yiisoft/yii2": ">=2.0.5",        "yiisoft/yii2-bootstrap": "*",        "yiisoft/yii2-swiftmailer": "*",        "yiisoft/yii2-smarty": "*",        "yiisoft/yii2-redis": "*"    },
Copy after login

然后使用命令 composer update,或者直接使用命令 composer update --prefer-dist yii-soft/yii2-redis。

接下来就是配置组件了。

//Redis'redis' => [    'class' => 'yii\redis\Connection',    'hostname' => '127.0.0.1',    'port' => 6379,    'database' => 0,//默认有16个库0-15,如果是集群的话,只有一个0。],
Copy after login

最后可以可以使用了。

$redis = Yii::$app->redis;$redis->set('city', 'Beijing');$value = $redis->get('city');echo 'The value of city in redis is: ', $value;
Copy after login

在Yii2中使用Pjax导致Yii2内联脚本载入失败的问题 http://www.linuxidc.com/Linux/2016-03/128949.htm

Yii2 实现修改密码功能 http://www.linuxidc.com/Linux/2015-07/120137.htm

Yii 用户登陆机制 http://www.linuxidc.com/Linux/2015-01/111602.htm

Yii中引入js和css文件 http://www.linuxidc.com/Linux/2015-01/111603.htm

Yii 不完全解决方案 http://www.linuxidc.com/Linux/2015-01/111606.htm

Yii CGridView 基本使用 http://www.linuxidc.com/Linux/2015-01/111607.htm

Yii框架分布式缓存的实现方案 http://www.linuxidc.com/Linux/2015-02/113828.htm

Yii 的详细介绍: 请点这里

Yii 的下载地址: 请点这里

本文永久更新链接地址: http://www.linuxidc.com/Linux/2016-06/132338.htm

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template