1
+ package com .sparta .binplay .config ;
2
+
3
+ import org .springframework .beans .factory .annotation .Value ;
4
+ import org .springframework .context .annotation .Bean ;
5
+ import org .springframework .context .annotation .Configuration ;
6
+ import org .springframework .data .redis .connection .RedisConnectionFactory ;
7
+ import org .springframework .data .redis .connection .lettuce .LettuceConnectionFactory ;
8
+ import org .springframework .data .redis .core .RedisTemplate ;
9
+ import org .springframework .data .redis .repository .configuration .EnableRedisRepositories ;
10
+ import org .springframework .data .redis .serializer .GenericJackson2JsonRedisSerializer ;
11
+ import org .springframework .data .redis .serializer .StringRedisSerializer ;
12
+
13
+ @ Configuration
14
+ @ EnableRedisRepositories
15
+ public class RedisConfig {
16
+ @ Value ("${spring.redis.host}" )
17
+ private String redisHost ;
18
+
19
+ @ Value ("${spring.redis.port}" )
20
+ private int redisPort ;
21
+
22
+ @ Bean
23
+ public RedisConnectionFactory redisConnectionFactory () {
24
+ return new LettuceConnectionFactory (redisHost , redisPort );
25
+ }
26
+
27
+ @ Bean
28
+ public RedisTemplate <String , Object > redisTemplate () {
29
+ RedisTemplate <String , Object > redisTemplate = new RedisTemplate <>();
30
+
31
+ redisTemplate .setConnectionFactory (redisConnectionFactory ());
32
+
33
+ redisTemplate .setKeySerializer (new StringRedisSerializer ());
34
+ redisTemplate .setValueSerializer (new GenericJackson2JsonRedisSerializer ());
35
+
36
+ // Hash를 사용할 경우 Serializer
37
+ redisTemplate .setHashKeySerializer (new StringRedisSerializer ());
38
+ redisTemplate .setHashValueSerializer (new StringRedisSerializer ());
39
+
40
+ return redisTemplate ;
41
+ }
42
+ }
0 commit comments