복붙노트

[REDIS] 사용 1.7.0.M1 봄 - 데이터 - 레디 스 때 레디 스 클러스터를 config (설정)하는 방법

REDIS

사용 1.7.0.M1 봄 - 데이터 - 레디 스 때 레디 스 클러스터를 config (설정)하는 방법

내가 사용하는 버전 1.7.0.M1 봄 - 데이터 - 레디 스 및 버전 2.8.0을 jedis 여기 내 구성은

<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
    <property name="connectionFactory" ref="redisConnectionFactory"></property>
    <property name="keySerializer">
        <bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
    </property>
    <property name="hashKeySerializer">
        <bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
    </property>
    <property name="valueSerializer">
        <bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
    </property>
    <property name="hashValueSerializer">
        <bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer"/>
    </property>
</bean>

사용 【redisTemplate.opsForValue (). 수 ( "foo는")】 테스트에

예외를 던져

 org.springframework.dao.InvalidDataAccessApiUsageException: MOVED 12182 192.168.1.223:7002; nested exception is redis.clients.jedis.exceptions.JedisMovedDataException: MOVED 12182 192.168.1.223:7002

사용 1.7.0.M1 봄 - 데이터 - 레디 스 때 어떻게 레디 스 클러스터를 config (설정) 할 수?

해결법

  1. ==============================

    1.기본적으로 모든 필요한 그 RedisClusterConfiguration에서 클러스터 노드의 초기 수집을 설정하고 JedisConnectionFactory 또는 LettuceConnectionFactory에 하나를 제공한다.

    기본적으로 모든 필요한 그 RedisClusterConfiguration에서 클러스터 노드의 초기 수집을 설정하고 JedisConnectionFactory 또는 LettuceConnectionFactory에 하나를 제공한다.

    @Configuration
    class Config {
    
        List<String> clusterNodes = Arrays.asList("127.0.0.1:30001", "127.0.0.1:30002", "127.0.0.1:30003");
    
        @Bean
        RedisConnectionFactory connectionFactory() {
          return new JedisConnectionFactory(new RedisClusterConfiguration(clusterNodes));
        }
    
        @Bean
        RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
    
          // just used StringRedisTemplate for simplicity here.
          return new StringRedisTemplate(factory);
        }
    }
    

    봄 부팅은 다음 릴리스에서 레디 스 클러스터 작업을위한 구성 속성 (spring.redis.cluster.nodes, spring.redis.cluster.max-리디렉션)을 제공 할 것입니다. 관련 항목 자세한 내용은 166a27 / 커밋합니다.

    스프링 - 데이터 예는 이미 봄 데이터 레디 스 클러스터 지원의 예를 포함 리포지토리.

  2. from https://stackoverflow.com/questions/35471666/how-to-config-redis-cluster-when-use-spring-data-redis-1-7-0-m1 by cc-by-sa and MIT license