Doctrine用密码连接到redis

Don*_*ndi 1 php caching redis symfony doctrine-orm

听起来很简单,但它让我连续几个小时.

如何使用密码连接到redis缓存服务器.它在没有密码的情况下成功连接和缓存了学说查询,但是当我输入密码时,它会抛出异常

InvalidConfigurationException in ArrayNode.php line 309:
Unrecognized option "password" under "doctrine.orm.entity_managers.default.query_cache_driver"
Run Code Online (Sandbox Code Playgroud)

我尝试了一个组合,但我目前的代码是config.yml .....

    entity_managers:
        default:
            metadata_cache_driver: apc
            query_cache_driver:
                type: redis
                host: localhost
                port: 6379
#                password: myStr0nG!passw0rd - adding this causes exception
                instance_class: Redis
            result_cache_driver:
                type: redis
                host: localhost
                port: 6379
#                password: myStr0nG!passw0rd - adding this causes exception
                instance_class: Redis
Run Code Online (Sandbox Code Playgroud)

Vam*_*a B 5

您不能为缓存驱动程序设置密码,因为它不受支持.

如果您想要替代方案,请考虑使用SncRedisBundle

配置示例

snc_redis:
    clients:
        cache:
            type: predis
            alias: default
            dsn: redis://secret@localhost/1
            logging: %kernel.debug%
    doctrine:
        metadata_cache:
            client: cache
            entity_manager: default          # the name of your entity_manager connection
            document_manager: default        # the name of your document_manager connection
        result_cache:
            client: cache
            entity_manager: [default, read]  # you may specify multiple entity_managers
        query_cache:
            client: cache
            entity_manager: default
Run Code Online (Sandbox Code Playgroud)

  • 它应该,但请不要因为它会破坏可维护性,我建议您安装doctrine-cache-bundle,创建一个redis缓存,并将其作为`service`类型cache.ie传递给配置:传递由doctrine cache bundle to doctrine bundle.also在[doctrine cache bundle](https://github.com/doctrine/DoctrineCacheBundle)的文档中,不支持redis缓存的密码,但我看了一下代码并且您应该能够在该缓存配置的`password`键中传递密码. (2认同)