部署时清除 redis 中的学说缓存

Clear doctrine cache in redis on deploy

我们将我们的学说缓存保存在 redis 中,并使用 capistrano 进行部署。一切正常,直到我们必须删除实体上的字段。

当在 composer 中执行 post 安装命令时,我们会得到如下错误:

[ReflectionException] ** [out Property Entities\PlayerRecord::$shirtNumber does not exist

$shirtNumber 是我们删除的字段。 为了能够继续,我们只需要清除学说缓存,但因为它在 redis 数据库中,所以缓存与生产共享。

问题是我们如何在每次部署时动态更改 redis 的连接设置?我想到的唯一想法是:

  1. 在部署开始时修改 parameters.yml
  2. 使用将在每次部署时更改的环境变量
  3. 将 redis 连接设置移动到另一个文件,该文件将符号链接到其中一个配置

您还有其他想法或者您认为哪个更好?

看来我是因为自己缺乏知识而试图把事情复杂化。

我使用 Doctrine Cache namespaces

解决了这个问题

我正在使用 SncRediBundle,解决方案就是使用这个配置:

  doctrine:
    metadata_cache:
      client: cache
      namespace: "%kernel.root_dir%"
      entity_manager: default