SpringBoot操作Redis只需要注解@Autowired即可
使用StringRedisTemplate存Hash值到Redis数据库中
注解StringRedisTemplate
@Autowired
StringRedisTemplate stringRedisTemplate;
把hash值存进redis
@Test
public void setRedisMap() {
{
try {
//创建一个pojo对象
User u = new User();
u.setName("张三");
u.setId("1");
u.setPassword("123");
Map<String, Object> map = new HashMap<String, Object>();
//将pojo对象存入map中,这里需要将pojo对象序列化一下
map.put("key1", JSON.toJSONString(u));
//这里将Map写入redis数据库
stringRedisTemplate.opsForHash().putAll("map1", map);
} catch (Exception e) {
e.printStackTrac