ZF2:Redis |更改dump.rdb位置

时间:2015-05-14 10:06:17

标签: zend-framework2 redis

我在我的ZF2项目上运行了Redis。

默认情况下,Redis将dump.rdb保存在项目的根目录中。如何更改它以保存在缓存/数据中?

我的RedisFactory.php:

byte[] arr = ...

string[] inputStrings = Encoding.GetEncoding("iso-8859-1").GetString(arr).Split('\0');

在我的module.config.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;
    }

}

1 个答案:

答案 0 :(得分: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并确保其正常工作&lt; - 重要步骤

您可以稍后使用CONFIG REWRITE合并redis.conf中的配置。