1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
@RunWith(SpringRunner.class) @SpringBootTest public class RedisTest { @Autowired private RedisTemplate redisTemplate;
@Test public void setRedis() { redisTemplate.opsForValue().set("name", "林剑"); redisTemplate.opsForValue().set("sex", "男"); User user1 = new User(); user1.setUserId(1); user1.setUserName("张三"); user1.setPassword("123"); User user2 = new User(); user2.setUserId(2); user2.setUserName("李四"); user2.setPassword("456"); redisTemplate.opsForHash().put("user", String.valueOf(user1.getUserId()), user1); redisTemplate.opsForHash().put("user", String.valueOf(user2.getUserId()), user2); }
@Test public void getRedis() { System.out.println(JSON.toJSONString(redisTemplate.opsForHash().get("user", "1"))); System.out.println(JSON.toJSONString(redisTemplate.opsForHash().get("user", "2"))); } }
|