我在尝试执行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 }}
不确定在这里做什么