// 使用Redis批處理方式獲取用戶信息
redis = jedisPool.getResource();
// 選擇Redis庫區間
redis.select(4);
// 管道
Pipeline pipe = redis.pipelined();
Map<Long, Response<String>> intrmMap = Maps.newHashMap();
users.stream().filter(Objects::nonNull).forEach(userVO->{
intrmMap.put(userVO.getId(), pipe.get("error" + userVO.getId() + userVO.getPartnerId()));
});
// 提交執行
pipe.sync();
Map<Long, String> map = Maps.newHashMap();
for (Map.Entry<Long, Response<String>> entry :intrmMap.entrySet()) {
Response<String> sResponse = (Response<String>)entry.getValue();
Long key = entry.getKey();
String value = sResponse.get();
map.put(key, value);
}
記錄一下Redis一次取多個key - value的使用方法
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.