1 首先redis要开启

cd redis-3.0.0

cd /usr/local/redis19 cd bin/
./redis-server redis.conf
ps -aux | grep redis

看到端口号出来就证明启动了

2 pom.xml中 加入

<!-- 加入redis起步依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-redis</artifactId>
</dependency>


application.properties 

加入  spring.redis.host=ip地址
spring.redis.port=6379  端口号


3  main文件 加入  @EnableCaching       

springboot连接redis单机版

4 controller方法上加上    @Cacheable(value="findAllUsers")

springboot连接redis单机版

相关文章: