首页 > 解决方案 > 清除缓存时删除redis键

问题描述

项目配置:symfony 5。

我将缓存配置为使用redis,config\packages\cache.yml就像这样

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命令不应该删除或使密钥过期?

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

谢谢你的帮助

标签: redissymfony5

解决方案


我没有找到任何确认 cache:clear 应该清除链接到我的配置的 redis 键的参考。

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

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

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

小心,在 Windows 上它不起作用,因为 Redis 版本在 RedisTrait:356 中为空


推荐阅读