nestjs:如何在typeorm中删除带有前缀的redis缓存
我有一个带有nestjs:如何在typeorm中删除带有前缀的redis缓存,nestjs,typeorm,redis-cache,Nestjs,Typeorm,Redis Cache,我有一个带有create、list和update方法的服务类来修改实体 我在列表方法中设置了redis缓存,缓存键是list\u cache\u 1,list\u cache\u 2,… 我的问题是,如何删除create或update方法中的所有相关缓存,如 this.connection.queryResultCache.remove([`list_cache:*`]); 通过QueryBuilder设置“缓存id”时: const users = await connection
create、list
和update
方法的服务类来修改实体
我在列表方法中设置了redis缓存,缓存键是list\u cache\u 1,list\u cache\u 2,…
我的问题是,如何删除create
或update
方法中的所有相关缓存,如
this.connection.queryResultCache.remove([`list_cache:*`]);
通过QueryBuilder设置“缓存id”时:
const users = await connection
.createQueryBuilder(User, "user")
.where("user.isAdmin = :isAdmin", { isAdmin: true })
.cache("list_cache_1", 25000)
.getMany();
或使用存储库:
const users = await connection
.getRepository(User)
.find({
where: { isAdmin: true },
cache: {
id: "list_cache_1",
milliseconds: 25000
}
});
然后,获取连接对象并按如下所示移除
import { getConnection } from "typeorm";
const connection = getConnection();
await connection.queryResultCache.remove([`list_cache_1`]);
但是,我不知道有什么类型化方法可以使用通配符删除列表缓存