@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("查询成功!");
}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐