springboot中redis简单使用

注意:使用之前一定要把redis安装到本地中,并且开启服务

pom.xml

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

application.propertis配置文件中

spring.redis.database=0
//redis的Ip
spring.redis.host=127.0.0.1
//redis的端口(默认端口就是6390)
spring.redis.port=6390

控制器中

	//注入redis使用模板
    @Autowired
    private StringRedisTemplate redisTemplate;
    
    @RequestMapping("/radis")
    public Object ra(){
        redisTemplate.opsForValue().set("name","daibin");
        return redisTemplate.opsForValue().get("name");
    }

    @RequestMapping("/radis1")
    public Object ra1(){
        return redisTemplate.opsForValue().get("name");
    }

猜你喜欢

转载自blog.csdn.net/qq_36984017/article/details/82938238