1、在pom.xml中配置相關的jar依賴;
<!-- 加載spring boot redis包 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
2、在Springboot核心配置檔案application.properties中配置redis連接配接資訊:
spring.redis.host=192.168.230.128
spring.redis.port=6379
spring.redis.password=123456
3、配置了上面的步驟,Spring boot将自動配置RedisTemplate,在需要操作redis的類中注入redisTemplate;
在使用的類中注入:
@Autowired
private RedisTemplate<String, String> redisTemplate;
@Autowired
private RedisTemplate<Object, Object> redisTemplate;
哨兵模式redis叢集配置:
spring.redis.password=123456
spring.redis.sentinel.master=mymaster
spring.redis.sentinel.nodes=192.168.30.128:26380,192.168.30.128:26382,192.168.30.128:26384