skip to Main Content

I want to use custom namespace in our RedisAdapter to cache in our Symfony4 app. However, when i want to set arguments like this in our services.yaml;

cache.adapter.redis:
        class: SymfonyComponentCacheAdapterRedisAdapter
        arguments:
            - '@Redis'
            - 'app'

I see this error message:

SymfonyComponentCacheTraitsRedisTrait::init() expects parameter 1 to be Redis, RedisArray, RedisCluster or PredisClientInterface, string given.

By the way, our cache config(config/packages/cache.yaml) is simple like below. So, how can I set namespace directly from any config?

    cache:
        app: cache.adapter.redis
        default_redis_provider: 'redis://%env(REDIS_HOST)%:%env(REDIS_PORT)%'

2

Answers


  1. Chosen as BEST ANSWER

    I solved it with this config:

    app.cache.adapter.redis:
        parent: 'cache.adapter.redis'
        public: true
        autowire: true
        autoconfigure: false
        tags:
            - {name: 'cache.pool', namespace: 'app'}
    

  2. If you need the namespace to be interoperable with a third-party app,
    you can take control over auto-generation by setting the namespace attribute of the cache.pool service tag.
    For example, you can override the service definition of the adapter:

    # config/services.yaml
    services:
        app.cache.adapter.redis:
            parent: 'cache.adapter.redis'
            tags:
                - { name: 'cache.pool', namespace: 'my_custom_namespace' }
    

    more details here: https://github.com/symfony/symfony-docs/pull/12527

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search