SERVER/Redis

Spring Boot with Redis Cluster

벨포트조던 2019. 3. 5.
반응형

일단 요기 설명대로 따라하자...

http://docs.spring.io/spring-data/redis/docs/current/reference/html/#cluster


혹시 클래스를 못찾는 경우가 생긴다면 Spring Boot가 기본으로 끼워 넣는 것들이 버전이 낮아서 그러니 라이브러리 업데이트를 하자...


compile 'org.springframework.data:spring-data-redis:1.7.2.RELEASE'

 

compile 'redis.clients:jedis:2.9.0'


위와 같이 (현 상황에서) 최신 버전으로 갈아 끼면 된다... (gradle 기준...)


그리고 나서 잘 되나 보면..

IntelliJ를 사용한다면 @ConfigurationProperties를 그냥 쓰면 안된다고 한다..


https://github.com/spring-projects/gradle-plugins/tree/master/propdeps-plugin

일단 위 플러그인을 gradle에 설정해주고...


http://docs.spring.io/spring-boot/docs/current/reference/html/configuration-metadata.html#configuration-metadata-annotation-processor

요기 가보면 뭔가 추가적으로 설정해주어야 하는 것들이 있다...

잘 따라서 설정해주면 된다..


그 후 application.properties에 prefix로 설정한 대로...


spring.redis.cluster.nodes=host:port,host:port,host:port,...


요렇게 해주면 된다....


그리고 기존에 StringRedisTemplate을 사용했다면 아래와 같이 bean을 하나 만들어주고 @Autowire해서 사용하면 된다...

http://docs.spring.io/spring-data/redis/docs/current/reference/html/#redis:string


코드로 하면 대충 아래와 같이 하면 된다...


@Bean

public StringRedisTemplate stringRedisTemplate(RedisConnectionFactory connectionFactory) {

    return new StringRedisTemplate(connectionFactory);

}


반응형

'SERVER > Redis' 카테고리의 다른 글

redis 시간 설정, expire  (0) 2019.03.29
redi 간단 설명 및 sring 값  (0) 2019.03.15
[redis]레디스 처음 알아본 자료들  (0) 2019.03.05

댓글