【发布时间】:2016-05-15 15:45:16
【问题描述】:
我必须在服务器上设置一个 Redis 来存储来自 Zend Framework 2 的信息。 目前,我可以存储信息,但我不能给它们一个过期时间,因为它们会在一段时间后自然更新。
我还没有找到有关此步骤的一些文档,而且在我看来相当晦涩。
我的代码:
页面:config/autoload/cache.global.php
return array(
'caches' => array(
'redis' => array (
'adapter' => array (
'name' => 'redis',
'lifetime' => 60, //doesn't work
'options' => array (
'server' => array (
'host' => 'x.x.x.x',
'port' => x
),
'ttl' => 10, // seems to have no effect
'namespace' => 'mycache',
),
),
)
)
);
在控制器中:
..
use Zend\Cache\StorageFactory;
..
$redis = StorageFactory::factory ($this->getServiceLocator ()
->get ('config')['caches']['redis']);
if ($redis->hasItem ('test')) {
var_dump($redis->getItem ('test'));
$redis->removeItem('test');
} else {
$redis->addItem('test', 'testtest');
}
..
我尝试了几种方法,但每次结果都一样,Redis中没有出现过期信息:
127.0.0.1:6379> get mycache:test
"testtest"
127.0.0.1:6379> ttl mycache:test
(integer) -1
感谢您的帮助!
【问题讨论】:
标签: php caching zend-framework redis zend-framework2