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

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);
}
发布了23 篇原创文章 · 获赞 0 · 访问量 1133

猜你喜欢

转载自blog.csdn.net/u013421917/article/details/102834777