清除缓存时删除Redis键

时间:2020-07-01 08:22:57

标签: redis symfony5

项目配置:symfony 5。

我在config\packages\cache.yml中将缓存配置为使用redis

framework:
    cache:
        prefix_seed: myAppPrefix_
        app: cache.adapter.redis
        system: cache.adapter.filesystem
        default_redis_provider: '%env(REDIS_URL)%'

当我运行php bin/console cache:clear --env=dev时,redis键不会被删除并且不会过期。

cache:clear命令是否应该删除或使密钥过期?

我可以删除所有与我的应用程序前缀匹配的密钥吗?

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

我找不到任何确认该缓存的参考:clear应该清除链接到我的配置的redis密钥。

最后,我创建了一个命令(注入“ AdapterInterface”)以使用该代码清理它们:

public function __construct(AdapterInterface $cache)
{
    ...
    $this->cache= $cache;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
    $this->redis->clear();
}

请注意,在Windows上它不起作用,因为Redis版本中的Redis版本为空:356