Yii2 里使用Redis扩展
2016-04-14 18:19
441 查看
Redis是个很不错的Nosql数据库,比Memcached的好处是能持久化数据。
Yii2里使用Redis ,首先要扩展Redis。可以在composer.json 里添加 redis
然后使用命令 composer update,或者直接使用命令 composer update --prefer-dist yii-soft/yii2-redis。
接下来就是配置组件了。
最后可以可以使用了。
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": "*" },
然后使用命令 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。 ],
最后可以可以使用了。
$redis = Yii::$app->redis; $redis->set('city', 'Beijing'); $value = $redis->get('city'); echo 'The value of city in redis is: ', $value;
相关文章推荐
- redis哨兵切换问题
- [ Redis ] Redis 未授权访问漏洞被利用,服务器登陆不上
- Spring Boot入门(连接MySQL, Redis 输出JSP)
- Python 练习册 3-存储激活码到Redis数据库
- redis学习日志【二、redis+jedis】
- Asp.net Session保存到Redis: 使用 RedisSessionStateProvider
- Redis - 作为 LRU 缓存
- 基于nginx tomcat redis分布式web应用的session共享配置
- 用 Redis 轻松实现秒杀系统的构思
- 使用一致性哈希实现Redis分布式部署
- redis 事务
- Redis的使用
- Redis命令-有序集合-zrevrangebylex
- redis
- SpringMVC整合Redis 出现 afterPropertiesSet signature: ()V) Incompatible argument to function 解决办法
- 基于Redis实现分布式锁-Redisson使用及源码分析
- Redis资料整理
- 把redis安装到ubuntu-14.04.1-server
- redis安装
- redis 3.0的集群部署