使用spring-boot-starter-data-redis操作redis

mac2024-04-05  32

pom文件

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>

代码

@Autowired //使用字符串的方式进行存储,因为使用redistemplate的泛型方式指定的话会将对象转为字节码 // 这样的话通过客户端查看不方便 private StringRedisTemplate template; @Test public void testValue(){ template.opsForValue().set("zsj","name"); String zsj = template.opsForValue().get("zsj"); System.out.println(zsj); } @Test public void testRedis() { template.opsForHash().put("user","name","zsj"); Object o = template.opsForHash().get("user", "name"); System.out.println(o); }
最新回复(0)