application.yaml:
spring:
redis:
password: "xxx" // Redis密码
sentinel:
master: mymaster
nodes:
- xxx.xxxx.xxx.xxx:27001
- xxx.xxxx.xxx.xxx:27001
- xxx.xxxx.xxx.xxx:27001
在启动类中注册配置类Bean
@SpringBootApplication
public class RedisDemoApplication {
@Bean
public LettuceClientConfigurationBuilderCustomizer clientConfigurationBuilderCustomizer() {
return clientConfigurationBuilder -> clientConfigurationBuilder.readFrom(ReadFrom.REPLICA_PREFERRED);
}
public static void main(String[] args) {
SpringApplication.run(RedisDemoApplication.class, args);
System.out.println("启动成功");
}
}