简体   繁体   English

缓存期间Redis错误“连接读取超时”

[英]Redis error “Connection read timed out” during caching

I have Zend Framework project and I decided to use Rediska as Redis client. 我有Zend Framework项目,我决定使用Rediska作为Redis客户端。 Rediska has cache backend adapter for ZF - Rediska_Zend_Cache_Backend_Redis. Rediska为ZF提供了缓存后端适配器 - Rediska_Zend_Cache_Backend_Redis。

I fetch from DB collection of objects and try to save it in cache but get error: Connection read timed out. 我从数据库集合中获取并尝试将其保存在缓存中但得到错误:连接读取超时。 My example of code: 我的代码示例:

$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);
}

Size of content after serialization is 26787 bytes. 序列化后的内容大小为26787字节。 Maybe Redis have size limitations for sending? 也许Redis有发送的大小限制?

If it helps, I am using Rediska with ZF as well. 如果它有帮助,我也使用Rediska和ZF。 Here is how I set it up. 这是我如何设置它。

$options = array(
                'servers' => array(
                    array(  'host'     => '127.0.0.1',
                            'port'     => 6379,
                            'alias'    => 'cache'
                ),
                //'name' => 'cache',
                //'namespace' => 'Cache_'
                )
            );

    $rediska = new Rediska($options);

    $frontendOptions = array('automatic_serialization' => true);
    $backendOptions  = array('rediska' => $rediska);

    $cache = Zend_Cache::factory( 'Core',
            'Rediska_Zend_Cache_Backend_Redis',
            $frontendOptions,
            $backendOptions,
            false,
            true
    );

A difference I see is in the backend options. 我看到的差异在于后端选项。 I point rediska to a rediska instance. 我将rediska指向rediska实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM