配置在Symfony缓存中使用哪个Redis适配器

问题描述 投票:1回答:1

我想对所有Redis连接使用Predis\Client而不是\Redis

Symfony文档on cache adapters描述您可以为createConnection方法提供其他选项。但是,所有这些都自动连接到服务容器中。我唯一要声明的是我想使用Redis进行缓存:

framework:
  cache:
    app: cache.adapter.redis
    default_redis_provider: '%redis_dsn%'

有什么方法可以配置RedisAdapter的默认选项?还是我可以将Symfony设置为始终将Predis\Client用于Redis吗?

使用?class=\Predis\Client配置DSN,这是最佳解决方案吗?

php symfony caching redis symfony4
1个回答
0
投票

向DSN添加其他选项没有错。只需使用字符串即可配置您的提供程序。但是,您可以定义自定义提供程序服务,并使用所需的任何配置。

来自https://symfony.com/doc/current/cache.html#custom-provider-options

# config/packages/cache.yaml
framework:
    cache:
        pools:
            cache.my_redis:
                adapter: cache.adapter.redis
                provider: app.my_custom_redis_provider

services:
    app.my_custom_redis_provider:
        class: \Redis
        factory: ['Symfony\Component\Cache\Adapter\RedisAdapter', 'createConnection']
        arguments:
            - 'redis://localhost'
            - { retry_interval: 2, timeout: 10 }

在您的情况下,您将类更改为Client \ Predis并更改适用的设置。

© www.soinside.com 2019 - 2024. All rights reserved.