public static void hRemoveDim(String key, String item){
ArrayList items = new ArrayList<>();
// 模糊查詢出準确的item
redisTemplate.execute(new RedisCallback() {
@Override
public Object doInRedis(RedisConnection connection) throws DataAccessException {
Cursor> entryCursor = connection.hScan(key.getBytes(), ScanOptions.scanOptions().match("*" + item + "*").count(1000).build());
while(entryCursor.hasNext()){
Map.Entry next = entryCursor.next();
String key = new String(next.getKey());
// 将查詢出的item放入list
items.add(key);
}
connection.close();
return null;
}
});
// 批量删除對應key中的item
redisTemplate.opsForHash().delete(key, item)
}
注意:本文歸作者所有,未經作者允許,不得轉載