Java 遍历 Redis Hash key中所有数据
Java 遍历 Redis Hash key中所有数据
·
@Autowired
private RedisTemplate<String, String> redisTemplate;
@GetMapping("/redis")
public CommonResult<?> queryRedisData() {
log.info("获取HashKey key:{}", "temp_data");
redisTemplate.setKeySerializer(new StringRedisSerializer());
HashOperations<String, Object, Object> ops = redisTemplate.opsForHash();
log.info("获取HashKey redisTemplate:{}", redisTemplate);
final Map<Object, Object> tempData = ops.entries("temp_data");
tempData.forEach((key, value) -> {
log.info("key -> {}, value -> {}", key, value);
});
return CommonResult.success("查询成功!");
}
更多推荐
已为社区贡献3条内容
所有评论(0)