【问题标题】:Using RedisTagAwareAdapter in Symfony 4.4在 Symfony 4.4 中使用 RedisTagAwareAdapter
【发布时间】:2021-09-01 03:42:44
【问题描述】:

我在让 Symfony 与 redis 的标签感知适配器很好地配合使用时遇到了问题

不幸的是,Symfony 5.2 包含此功能,但由于我们没有切换到非 lts 版本,所以这是不可能的。我已经尝试检查配置,但它对我来说不太有效。

这是我目前的设置:

# cache.yaml
framework:
  cache:
    prefix_seed: !php/const App\Kernel::APP_VERSION
    app: cache.adapter.redis_tag_aware
  redis.cache_app:
    class: Redis
    factory: ['Symfony\Component\Cache\Adapter\RedisAdapter', 'createConnection']
    arguments:
      - '%env(REDIS_DNS)%'

  cache.adapter.redis_tag_aware:
    class: Symfony\Component\Cache\Adapter\RedisTagAwareAdapter
    arguments:
      $redisClient: '@redis.cache_app'
      $marshaller: '@?cache.default_marshaller'
    calls:
      - ['setLogger', ['@?logger']]
    tags:
      - { name: cache.pool, provider: cache.default_redis_provider, clearer: cache.default_clearer, reset: reset }
      - { name: monolog.logger, channel: cache }

但它对不存在通过某些 CompilerPass 的参数 0 大喊大叫。

难道不能将应用缓存用作标记缓存吗?我想我可以创建一个单独的池并使用它,但这似乎是一个奇怪的选择。

【问题讨论】:

    标签: symfony caching configuration symfony-4.4


    【解决方案1】:

    好的,很明显这是一个配置问题。

    以下将起作用

    # services.yaml
      redis.cache_app:
        class: Redis
        factory: ['Symfony\Component\Cache\Adapter\RedisAdapter', 'createConnection']
        arguments:
          - '%env(REDIS_DNS)%'
    
      cache.app.redis_tag_aware:
        class: Symfony\Component\Cache\Adapter\RedisTagAwareAdapter
        arguments:
          - '@redis.cache_app'
          - ''
          - 0
          - '@?cache.default_marshaller'
        calls:
          - ['setLogger', ['@?logger']]
        tags:
          - { name: cache.pool, provider: redis.cache_app, clearer: cache.default_clearer, reset: reset }
          - { name: monolog.logger, channel: cache }
    
    # cache.yaml
    framework:
      cache:
        prefix_seed: !php/const App\Kernel::APP_VERSION
        app: cache.app.redis_tag_aware
    

    【讨论】:

      猜你喜欢
      • 2020-11-21
      • 2020-09-03
      • 2020-05-10
      • 2020-12-22
      • 2020-11-25
      • 2020-05-05
      • 1970-01-01
      • 2021-02-20
      • 2021-03-18
      相关资源
      最近更新 更多