我正在尝试将 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: Argument 1 passed to Doctrine\ORM\Mapping\ClassMetadataFactory::wakeupReflection() must implement interface Doctrine\Common\Persistence\Mapping\ClassMetadata, string given, called in vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php on line 214
我的功能测试如下所示:
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);
对于您的情况,您可能需要将配置选项设置为驱动程序配置的一部分。
关于php - Symfony2 Doctrine 元数据缓存与 Redis 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34659836/