有人可以告诉我如何在Zend 2中建立与Redis群集的连接吗?我们正在从单个Redis实例迁移到AWS Redis集群。如果我只是将群集端点分配为Redis主机,则会返回MOVED错误
Uncaught exception 'RedisException' with message 'MOVED
因为目标是可扩展性,所以我不想遵循为集群中的Redis服务器指定各个端点的路线。
我们当前的Redis工厂看起来像这样
use Zend\Cache\Storage\Adapter\Redis;
use Zend\Cache\Storage\Adapter\RedisOptions;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
/**
* RedisFactory
*/
class RedisFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $serviceLocator)
{
$config = $serviceLocator->get('Config');
$redisConfig = $config['redis'];
$redisOptions = new RedisOptions();
$redisOptions->setServer([
'host' => $redisConfig["host"],
'port' => $redisConfig["port"],
'timeout' => '30'
]);
$redisOptions->setLibOptions(array(
\Redis::OPT_SERIALIZER => \Redis::SERIALIZER_PHP
));
$redisCache = new Redis($redisOptions);
return $redisCache;
}
}
在搜索Zend 2 Redis集群/集群时,我找不到任何有用的东西,但是之前一定有人遇到过这种情况吗?