多个实体管理器的Redis配置(symfony 2)

时间:2016-02-23 08:41:49

标签: php symfony doctrine

我想在symfony 2中配置redis,以防我定义了2个实体管理器(在config.yml文件中):

doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                (...connection settings...)
             warehouse:
                (...connection settings...)

    orm:
        auto_generate_proxy_classes: true
        default_entity_manager: default
        entity_managers:
            default:
                connection: default
                auto_mapping: true
                mappings:
                    some_name:
                        type: xml
                        dir: (...dir1...)
                        prefix: (...prefix...)
                        is_bundle: false
            warehouse:
                connection: warehouse
                mappings:
                    some_name:
                        type: xml
                        dir: (...dir1...)
                        prefix: (...prefix...)
                        is_bundle: false

目前,为一个实体管理器配置了snc-redis,默认值为:

snc_redis:
    clients:
        default:
            type: predis
            alias: default
            dsn: redis://redis
        doctrine:
            type: predis
            alias: doctrine
            dsn: redis://redis
    doctrine:
        metadata_cache:
            client: doctrine
            entity_manager: default
            document_manager: default
        result_cache:
            client: doctrine
            entity_manager: [default]
        query_cache:
            client: doctrine
            entity_manager: default

如何更改它以服务多个实体经理? 我还看到redis可以在每个学说中定义 - > orm - >示例中的实体管理器部分:

entity_managers:
    default:
        metadata_cache_driver: redis
        result_cache_driver: redis
        query_cache_driver: redis

相当于在snc_redis中定义它 - >学说部分?

1 个答案:

答案 0 :(得分:0)

entity_manager选项可以将数组设置为值 - 您可以列出要连接该客户端的实体管理器。

snc_redis:
    clients:
        default:
            type: predis
            alias: default
            dsn: redis://redis
        doctrine:
            type: predis
            alias: doctrine
            dsn: redis://redis
    doctrine:
        metadata_cache:
            client: doctrine
            entity_manager: [default, warehouse]
            document_manager: default
        result_cache:
            client: doctrine
            entity_manager: [default, warehouse]
        query_cache:
            client: doctrine
            entity_manager: [default, warehouse]