我希望在RedisAdapter中使用自定义名称空间来缓存Symfony4应用程序。但是,当我想在我们的services.yaml中设置这样的参数时;
cache.adapter.redis:
class: Symfony\Component\Cache\Adapter\RedisAdapter
arguments:
- '@Redis'
- 'app'我看到了这个错误消息:
Symfony\Component\Cache\Traits\RedisTrait::init() expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\ClientInterface, string given.
顺便说一下,我们的缓存配置(config/packages/cache.yaml)很简单,如下所示。那么,如何从任何配置直接设置命名空间呢?
cache:
app: cache.adapter.redis
default_redis_provider: 'redis://%env(REDIS_HOST)%:%env(REDIS_PORT)%'发布于 2020-01-03 07:26:47
我用这个配置解决了这个问题:
app.cache.adapter.redis:
parent: 'cache.adapter.redis'
public: true
autowire: true
autoconfigure: false
tags:
- {name: 'cache.pool', namespace: 'app'}发布于 2020-07-23 17:17:33
如果需要命名空间与第三方应用程序进行互操作,则可以通过设置namespace服务标记的cache.pool属性来控制自动生成。例如,可以重写适配器的服务定义:
# config/services.yaml
services:
app.cache.adapter.redis:
parent: 'cache.adapter.redis'
tags:
- { name: 'cache.pool', namespace: 'my_custom_namespace' }这里有更多详细信息:https://github.com/symfony/symfony-docs/pull/12527
https://stackoverflow.com/questions/59563682
复制相似问题