引入依赖
<redisson.version>3.26.0</redisson.version>
<!-- Redisson -->
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<version>${redisson.version}</version>
</dependency>
<!--Redisson-->
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
</dependency>
聚合工程和common
各引入一份
编写配置文件Config
@Data
@Configuration
public class AppConfig {
@Value("${spring.redis.host}")
private String redisHost;
@Value("${spring.redis.port}")
private String redisPort;
@Value("${spring.redis.password}")
private String redisPwd;
@Bean
public RedissonClient redissonClient(){
Config config = new Config();
// 单机模式
config.useSingleServer().setAddress("redis://"+redisHost+":"+redisPort);
// 集群模式
//config.useClusterServers().addNodeAddress("redis://192.168.164.128:6379","redis://.......");
returnRedisson.create(config);
}
}
注入RedissonClient即可使用
private final RedissonClient redissonClient;