繁体   English   中英

使用Redis问题的Symfony2 Doctrine元数据缓存

[英]Symfony2 Doctrine Metadata Cache with Redis Issue

我正在尝试使用Redis作为缓存教学元数据,查询和结果的驱动程序。 Follwing是我的配置。

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 \\ Mapping \\ ClassMetadataFactory :: wakeupReflection()的参数1必须实现接口Doctrine \\ Common \\ Persistence \\ Mapping \\ ClassMetadata,给定的字符串,在vendor / doctrine / common / lib / Doctrine / Common / Persistence /中调用第214行上的Mapping / 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);

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM