File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
src/main/java/com/backend/global/redis Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 11package com .backend .global .redis ;
22
3+ import org .springframework .beans .factory .annotation .Value ;
34import org .springframework .context .annotation .Bean ;
45import org .springframework .context .annotation .Configuration ;
6+ import org .springframework .data .redis .connection .RedisPassword ;
7+ import org .springframework .data .redis .connection .RedisStandaloneConfiguration ;
58import org .springframework .data .redis .connection .lettuce .LettuceConnectionFactory ;
69import org .springframework .data .redis .core .RedisTemplate ;
710import org .springframework .data .redis .serializer .StringRedisSerializer ;
811
912@ Configuration
1013public class RedisConfig {
1114
15+ @ Value ("${spring.data.redis.host}" )
16+ private String redisHost ;
17+
18+ @ Value ("${spring.data.redis.port}" )
19+ private int redisPort ;
20+
21+ @ Value ("${spring.data.redis.password:}" )
22+ private String redisPassword ;
23+
1224 @ Bean
1325 public LettuceConnectionFactory redisConnectionFactory () {
14- return new LettuceConnectionFactory ();
26+ RedisStandaloneConfiguration config = new RedisStandaloneConfiguration (redisHost , redisPort );
27+ if (redisPassword != null && !redisPassword .isEmpty ()) {
28+ config .setPassword (RedisPassword .of (redisPassword ));
29+ }
30+ return new LettuceConnectionFactory (config );
1531 }
1632
1733 @ Bean
You can’t perform that action at this time.
0 commit comments