2015-05-14 79 views
0

我有我的ZF2項目上運行的Redis。ZF2:Redis |更改dump.rdb位置

Redis默認將其dump.rdb保存在我的項目的根目錄中。我該如何改變以保存緩存/數據?

我RedisFactory.php:

<?php 
namespace Application\Service\Factory; 

use Zend\ServiceManager\FactoryInterface; 
use Zend\ServiceManager\ServiceLocatorInterface; 
use Zend\Cache\Storage\Adapter\RedisOptions; 
use Zend\Cache\Storage\Adapter\Redis; 

class RedisFactory implements FactoryInterface { 

    public function createService(ServiceLocatorInterface $serviceLocator) { 

     $redisOptions = new RedisOptions(); 
     $redisOptions->setServer (array (
       'host' => '127.0.0.1', 
       'port' => '6379', 
       'timeout' => '30' 
     )); 

     $redisOptions->setTtl(86400); 

     $redisOptions->setLibOptions (array (
       \Redis::OPT_SERIALIZER => \Redis::SERIALIZER_PHP, 
     )); 

     $redis = new Redis ($redisOptions); 

     return $redis; 
    } 

} 

在我module.config.php:

'service_manager' => array(
    'factories' => array(
     'Application\Cache\Redis' => 'Application\Service\Factory\RedisFactory', 
    ), 
    'abstract_factories' => array(
     'Zend\Cache\Service\StorageCacheAbstractServiceFactory', 
     'Zend\Log\LoggerAbstractServiceFactory' 
    ), 
    'aliases' => array(
     'translator' => 'MvcTranslator', 
    ), 
), 

回答

1

redis.conf示例配置文件:

# The working directory. 
# 
# The DB will be written inside this directory, with the filename specified 
# above using the 'dbfilename' configuration directive. 
# 
# The Append Only File will also be created inside this directory. 
# 
# Note that you must specify a directory here, not a file name. dir ./ 

不過,如果你有一個運行服務器,您也可以嘗試使用

CONFIG SET dir /new/dir 

,然後觸發一個BGSAVE,並確保它的工作原理< - 重要一步

您可以使用CONFIG REWRITE後,以鞏固在配置redis.conf

+0

但是這會改變全局目錄嗎?看起來我在〜dir和每個虛擬主機都有dump.rdb。 – zed