Symfony2 Doctrine使用Redis作为元数据缓存出现问题

3

我正在尝试将Redis作为缓存Doctrine元数据、查询和结果的驱动程序。以下是我的配置。

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的行时,我运行一个测试时出现以下错误。

类型错误:传递给Doctrine\ORM\Mapping\ClassMetadataFactory :: wakeupReflection()的第1个参数必须实现接口Doctrine\Common\Persistence\Mapping\ClassMetadata,给定字符串,在vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping /AbstractClassMetadataFactory.php的第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进行额外的配置吗?非常感谢您的帮助!
1个回答

0
我认为解决这个问题需要为Redis设置序列化器,因为默认的序列化器可能不知道PHP类,当对象从缓存中移除并反序列化时,它与序列化之前的类型不同。
$redis->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_PHP);

对于您的情况,您可能需要将配置选项设置为驱动程序配置的一部分。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接