我有 Zend Framework 项目,我决定使用Rediska作为 Redis 客户端。Rediska 有 ZF 的缓存后端适配器 - Rediska_Zend_Cache_Backend_Redis。
我从数据库对象集合中获取并尝试将其保存在缓存中,但出现错误:连接读取超时。我的代码示例:
$rediskaOptions = array(
'name' => 'cache',
'namespace' => 'Cache_',
'servers' => array( 'cache' => array(
'host' => Rediska_Connection::DEFAULT_HOST,
'port' => Rediska_Connection::DEFAULT_PORT,
'password' => 'qwerty'
)
)
);
$cache = Zend_Cache::factory('Core', 'Rediska_Zend_Cache_Backend_Redis',
array('lifetime' => NULL, 'automatic_serialization' => true),
array('rediska' => $rediskaOptions), false, true
);
$cacheId = 'news_main';
if (!($topics = $cache->load($cacheId))) {
$topics = DAOFactory::getInstance()->getTopicDAO()->fetchTopic(1);
$cache->save($topics, $cacheId);
}
序列化后的内容大小为 26787 字节。也许 Redis 对发送有大小限制?