public Map<String, String> hgetall(String key){ return redisTemplate.execute((RedisCallback<Map<String, String>>) con -> { Map<byte[], byte[]> result = con.hGetAll(key.getBytes()); if (CollectionUtils.isEmpty(result)) { returnnew HashMap<>(0); }
Map<String, String> ans = new HashMap<>(result.size()); for (Map.Entry<byte[], byte[]> entry : result.entrySet()) { ans.put(new String(entry.getKey()), new String(entry.getValue())); } return ans; }); }
public Map<String, String> hmget(String key, List<String> fields){ List<String> result = redisTemplate.<String, String>opsForHash().multiGet(key, fields); Map<String, String> ans = new HashMap<>(fields.size()); int index = 0; for (String field : fields) { if (result.get(index) == null) { continue; } ans.put(field, result.get(index)); } return ans; }