如何覆盖 RedisAdapter 中的命名空间参数以供 Symfony4 应用程序缓存 [英] How to override namespace argument in RedisAdapter for a Symfony4 app to cache
本文介绍了如何覆盖 RedisAdapter 中的命名空间参数以供 Symfony4 应用程序缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我们的 RedisAdapter 中使用自定义命名空间来缓存在我们的 Symfony4 应用程序中.但是,当我想在我们的 services.yaml 中设置这样的参数时;
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: Symfony\Component\Cache\Adapter\RedisAdapter
arguments:
- '@Redis'
- 'app'
我看到此错误消息:
Symfony\Component\Cache\Traits\RedisTrait::init() 期望参数 1 是 Redis、RedisArray、RedisCluster 或 Predis\ClientInterface,给定的字符串.
顺便说一下,我们的缓存配置(config/packages/cache.yaml)很简单,如下所示.那么,如何直接从任何配置中设置命名空间?
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)%'
推荐答案
我用这个配置解决了:
app.cache.adapter.redis:
parent: 'cache.adapter.redis'
public: true
autowire: true
autoconfigure: false
tags:
- {name: 'cache.pool', namespace: 'app'}
这篇关于如何覆盖 RedisAdapter 中的命名空间参数以供 Symfony4 应用程序缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文