File tree Expand file tree Collapse file tree
java/com/back/global/config Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44import org .springframework .context .annotation .Bean ;
55import org .springframework .context .annotation .Configuration ;
66import org .springframework .data .redis .connection .RedisConnectionFactory ;
7+ import org .springframework .data .redis .connection .RedisPassword ;
8+ import org .springframework .data .redis .connection .RedisStandaloneConfiguration ;
79import org .springframework .data .redis .connection .lettuce .LettuceConnectionFactory ;
810import org .springframework .data .redis .core .RedisTemplate ;
911import org .springframework .data .redis .serializer .GenericJackson2JsonRedisSerializer ;
@@ -18,9 +20,19 @@ public class RedisConfig {
1820 @ Value ("${spring.data.redis.port}" )
1921 private int port ;
2022
23+ @ Value ("${spring.data.redis.password:}" )
24+ private String password ;
25+
2126 @ Bean
2227 public RedisConnectionFactory redisConnectionFactory () {
23- return new LettuceConnectionFactory (host , port );
28+ RedisStandaloneConfiguration config =
29+ new RedisStandaloneConfiguration (host , port );
30+
31+ if (password != null && !password .isBlank ()) {
32+ config .setPassword (RedisPassword .of (password ));
33+ }
34+
35+ return new LettuceConnectionFactory (config );
2436 }
2537
2638 @ Bean
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ spring:
2424 redis :
2525 host : localhost
2626 port : 6379
27- password : ${REDIS_PASSWORD}
27+ password : ${REDIS_PASSWORD: }
2828
2929logging :
3030 level :
You can’t perform that action at this time.
0 commit comments