序列化PHPUnit的Predis集群选项

时间:2018-09-10 20:18:17

标签: redis phpunit predis

我在尝试执行Serialization of Closure is not allowed时收到以下消息:phpunit。建议我安装SuperClosure\Serializer并序列化闭包功能。 我这样做了,现在又断了,因为Predis Cluster Options constructor必须是可调用函数或值redis或predis的字符串,因此序列化会破坏字符串参数选项

这是我的代码

// load redis cluster
use Selector\Cache\Redis\ClusterClient as SelectorRedisClusterClient;
use Selector\Cache\Redis\NaiveDistributor as SelectorNaiveDistributor;
use Selector\Cache\Redis\PredisCluster as SelectorPredisCluster;
use Selector\Cache\Redis\PredisStrategy as SelectorPredisStrategy;
use SuperClosure\Serializer;
$serializer = new Serializer();
$clusterFunc = function() {
    $distributor = new SelectorNaiveDistributor();
    $strategy = new SelectorPredisStrategy($distributor);
    $cluster = new SelectorPredisCluster($strategy);
    return $cluster;
};
$clusterFuncSer = $serializer->serialize($clusterFunc);
$options = array(
    //'cluster' => function () {
     //   $distributor = new SelectorNaiveDistributor();
     //   $strategy = new SelectorPredisStrategy($distributor);
     //   $cluster = new SelectorPredisCluster($strategy);    
     //   return $cluster;
    //}
    'cluster'=>$clusterFuncSer
);
$redisServerData=$buildData['cache']['redis']['server'];
if(!\Selector\Zf\Stdlib\ArrayUtils::isList($redisServerData)){
    $tmp=[[
    'host'=>$redisServerData['host'],
    'port'=>$redisServerData['port'],
    'database'=>$redisServerData['database'],
    'alias'=>$redisServerData['alias'],
    ]];
    $redisServerData=$tmp;
}
$redis = new SelectorRedisClusterClient($redisServerData,$options);

新错误是:

Fatal error: Uncaught InvalidArgumentException: String value for the cluster option must be either predis or redis in /srv/awsconnect/connect/vendor/predis/predis/src/Configuration/Option/Cluster.php:45

因此,看起来好像将函数序列化为字符串,但是Redis Client中断了,因为它正在寻找一个数组,就像我一样,或者是一个值为redis或{{1 }}

不确定在这里做什么

0 个答案:

没有答案