我正在尝试使用Redis作为缓存条令元数据、查询和结果的驱动程序。以下是我的配置。
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
result_cache_driver:
type: redis
host: %redis_host%
instance_class: Redis
query_cache_driver: redis
#metadata_cache_driver: redis
当我从#metadata_cache_driver:redis行删除注释时,我在运行测试时遇到了一个错误,并出现以下错误。
TypeError:传递给Doctrine''ORM''MMapping''ClassMetadataFactory::wakeupReflection()的参数1必须实现接口Doctrine''Common''Persistence''MMapping''CClassMetadata,给定字符串,在第214行上的vendor/Common/lib/Doctrine/CommonPersistence/MMapping/AbstractClassMetadataFactory.php中调用
我的功能测试如下:
public function testX()
{
//The data in prepared in setup..
$param1 = 'test-id';
$param2 = 'test-key';
$result = $this->em->getRepository('MyBundle:Test')
->findOneByXX($param1, $param2);
$this->assertTrue($result instanceof Test);
}
我的查询如下所示:
$qb->select('c')
->from('MyBundle:Test', 'c')
->where('c.id = :id')
->andWhere('c.key = :key')
->setParameter('id', $id)
->setParameter('key', $key);
$query = $qb->getQuery()
->useResultCache(true);
return $query->getOneOrNullResult();
Redis需要额外配置吗?如有任何帮助,不胜感激??
我认为要解决这个问题,您需要为redis设置序列化程序,默认的序列化程序可能不知道PHP类,并且当对象从缓存中删除并未序列化时,它的类型和序列化前不同。
$redis->setOption('Redis::OPT_SERIALIZER, 'Redis::SERIALIZER_PHP);
对于您的情况,您可能需要将配置选项设置为驱动程序配置的一部分。