Nestjs:如何删除typeorm中带前缀的redis缓存

Ken*_*ood 6 redis-cache typeorm nestjs

我有一个服务类create,list,其中包含update修改实体的方法

我在list方法中设置了redis缓存,缓存key是list_cache_1,list_cache_2,...

我的问题是,如何删除createupdate方法中的所有相关缓存,例如

this.connection.queryResultCache.remove([`list_cache:*`]);
Run Code Online (Sandbox Code Playgroud)

小智 1

当您通过 QueryBuilder 设置“缓存 id”时:

const users = await connection
    .createQueryBuilder(User, "user")
    .where("user.isAdmin = :isAdmin", { isAdmin: true })
    .cache("list_cache_1", 25000)
    .getMany();
Run Code Online (Sandbox Code Playgroud)

或者使用存储库:

const users = await connection
    .getRepository(User)
    .find({
        where: { isAdmin: true },
        cache: {
            id: "list_cache_1",
            milliseconds: 25000
        }
    });
Run Code Online (Sandbox Code Playgroud)

然后,获取连接对象并删除,如下所示

import { getConnection } from "typeorm";

const connection = getConnection();
await connection.queryResultCache.remove([`list_cache_1`]);
Run Code Online (Sandbox Code Playgroud)

但是,我不知道使用通配符删除 list_cache_* 的 typeorm 方法。