Skip to content

Commit

Permalink
bugfix/修改RedissonConfig默认配置从nacos取
Browse files Browse the repository at this point in the history
  • Loading branch information
freestylefly committed Dec 5, 2024
1 parent c39a2f3 commit 0529dfb
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Expand All @@ -13,11 +14,20 @@
*/
@Configuration
public class RedissonConfig {
@Value("${spring.redis.host}")
private String redisHost;

@Value("${spring.redis.port}")
private int redisPort;

@Value("${spring.redis.password:}") // 如果没有密码,默认值为空
private String redisPassword;
@Bean
public RedissonClient redissonClient() {
Config config = new Config();
config.useSingleServer()
.setAddress("redis://localhost:6379")
.setAddress("redis://" + redisHost + ":" + redisPort)
.setPassword(redisPassword.isEmpty() ? null : redisPassword)
.setDatabase(0);

return Redisson.create(config);
Expand Down

0 comments on commit 0529dfb

Please sign in to comment.