我想删除所有属于特定模式或实体的redis数据,而不管每个条目的键/数据。这是我的客户端的样子。
//set up
const { Client, Entity, Schema } = require('redis-om');
class userEntity extends Entity {}
userSchema = new Schema(
userEntity,
{
id: { type: 'string' },
info: { type: 'string' },
},
{
dataStructure: 'JSON',
},
);
userRepository = this.redisClient.fetchRepository(userSchema);
await userRepository.createIndex();
//save data
let userData = this.userRepository.createEntity();
userData.id = '123';
userData.info = 'some user';
id = await this.userRepository.save(userData);
await this.userRepository.expire(id, 3600);
字符串
那么,如何一次性删除所有记录呢?属于userSchema或userEntity的记录?
1条答案
按热度按时间9njqaruj1#
不幸的是,RediSearch还没有一个命令可以删除与特定搜索匹配的记录。因此Redis OM也没有。删除找到的记录的唯一方法是获取所有匹配的entityIds并调用
.remove
。这是相当容易的,但是:字符串
另外,我注意到你在Redis OM中使用的语法是来自早期版本的。你可能需要考虑更新到Redis OM 0.4.x,因为一些语法已经改变了。细节可以在Redis OM的README中找到。