zf2 redis 练手2
来源:互联网 发布:中国现状 知乎 编辑:程序博客网 时间:2024/05/18 04:16
接着上文,不可能每次都都去实例化redis,这很麻烦,而且redis的配置没有分离,这样耦合度很高,不利于后续的代码修改,所以有修改了。
首先还是要启动redis-server,
在global.php
- 12345678910111213141516171819202122232425262728
return
array
(
'redis_config'
=>
array
(
'Server'
=>
'127.0.0.1:6379'
,
'Database'
=>
'0'
,
'Namespace'
=>
'session'
,
'Writable'
=>true,
'Readable'
=>true,
),
'service_manager'
=>
array
(
'factories'
=>
array
(
'Zend\Db\Adapter\Adapter\Redis'
=>
function
(
$sm
) {
$config
=
$sm
->get(
'Configuration'
);
if
(isset(
$config
[
'redis_config'
])){
//redis option
$config_redis
=
$config
[
'redis_config'
];
$redisOption
=
new
\Zend\Cache\Storage\Adapter\RedisOptions();
$redisOption
->setServer(
$config_redis
[
'Server'
])
->setDatabase(
$config_redis
[
'Database'
])
->setNamespace(
$config_redis
[
'Namespace'
])
->setWritable(
$config_redis
[
'Writable'
])
->setReadable(
$config_redis
[
'Readable'
]);
return
new
\Zend\Cache\Storage\Adapter\Redis(
$redisOption
)
}
},
),
),
);
之后在调用的地方
- 1234567
public
function
redisAction()
{
//获取redis
$redis
=
$this
->getServiceLocator()->get(
'Zend\Db\Adapter\Adapter\Redis'
);
$redis
->setItem(
'zzc'
,
'zhangzhican110@gmail.com'
);
die
;
}
0 0
- zf2 redis 练手2
- 扩展 ZF2 Redis Zend Framework 2 Redis Extend - key正则
- zendFramework2 redis练手
- 练手2
- 【ZF2】Zend Framework 2 Helloword 入门实例
- 练手
- 练手
- 练手~~~
- 练手
- 解决php zf2中redis调用提示'RedisException' with message 'read error on connection'
- Win7+Apache2.4.3+phpMyAdmin3.5.2.2+ZF2.0.0
- ZF2(Zend framework 2)启动流程和框架配置分析
- ZF2(Zend framework 2)启动流程和框架配置分析
- 第2讲 ZF2.4 最新框架搭建
- 学习zf2
- ZF2搭建
- 练手python_ 将条形码保存在redis数据库中
- 练手、练手
- MINA源码分析1:服务器端的启动过程
- JSON 转换
- 我们终是不再联系
- 299刀 - 企业版IDP的申请及“In House”发布
- Windows 对象
- zf2 redis 练手2
- linux-centos-使用学习
- MFC视图切换全总结(图文)
- J2EE概念综述
- python numpy,matplotlib,setuptools windows环境下的安装
- poj1321 棋盘问题(状态压缩)
- 常见HTTP状态码整理
- Oracle特殊字符转义:&和'
- K均值算法