简体   繁体   English

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

[英]Symfony2 Doctrine Metadata Cache with Redis Issue

I'm trying to use Redis as a driver for caching doctrine metadata, query and results. 我正在尝试使用Redis作为缓存教学元数据,查询和结果的驱动程序。 Follwing is my configuration. 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

When I remove the comment from line #metadata_cache_driver: redis, I get an error running a test I have with following error. 当我从#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 TypeError:传递给Doctrine \\ ORM \\ Mapping \\ ClassMetadataFactory :: wakeupReflection()的参数1必须实现接口Doctrine \\ Common \\ Persistence \\ Mapping \\ ClassMetadata,给定的字符串,在vendor / doctrine / common / lib / Doctrine / Common / Persistence /中调用第214行上的Mapping / AbstractClassMetadataFactory.php

My Functional Test looks like Following: 我的功能测试如下所示:

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);
}

And My Query looks like following: 我的查询如下所示:

$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();

Do I need additional configuration for Redis? 我需要Redis的其他配置吗? Any Help would be appreciated?? 任何帮助,将不胜感激??

I believe to resolve this you need to set the serializer for redis, the default serializer is probably not aware of the the PHP classes and when the object is removed from cache, and unserialized, it is not the same type as it was prior to serialization. 我相信要解决这个问题你需要为redis设置序列化程序,默认的序列化程序可能不知道PHP类,当对象从缓存中删除,并且反序列化时,它与序列化之前的类型不同。

$redis->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_PHP);

For you case you will probably need to set the configuration option as a part of the driver configuration. 对于您的情况,您可能需要将配置选项设置为驱动程序配置的一部分。

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

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