2017-11-03 22 views
0

spring-boot 프로젝트에서 redisTemplate을 사용하여 lua 스크립트를 실행하려고합니다. jedis가 redis 클러스터에 대한 lua 스크립트 실행을 지원하지 않는 것 같습니다 ... 다른 대안이 있습니까? 감사!spring-boot redisTemplate 스크립트 실행 오류 : EvalSha가 클러스터 환경에서 지원되지 않습니다.

레디 스의 설정 :

spring: 
    redis: 
    cluster: 
     nodes: 
     - 192.168.0.111:6390 
     - 192.168.0.111:6391 
     - 192.168.0.111:6392 

코드 :

@Component 
public class Example { 

@Autowired 
private RedisTemplate redisTemplate; 

@Autowired 
RedisScript<Boolean> script; 

public boolean checkAndSet(String expectedValue, String newValue) { 
    return (boolean) redisTemplate.execute(script, singletonList("key1"), asList(expectedValue, newValue)); 
} 
} 

오류 로그 : 클러스터 환경에서 EVALSHA을 사용하는 상추 드라이버

org.springframework.dao.InvalidDataAccessApiUsageException: EvalSha is not supported in cluster environment. 

at org.springframework.data.redis.connection.jedis.JedisClusterConnection.evalSha(JedisClusterConnection.java:3568) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:498) 
at org.springframework.data.redis.core.CloseSuppressingInvocationHandler.invoke(CloseSuppressingInvocationHandler.java:57) 
at com.sun.proxy.$Proxy237.evalSha(Unknown Source) 
at org.springframework.data.redis.core.script.DefaultScriptExecutor.eval(DefaultScriptExecutor.java:81) 
at org.springframework.data.redis.core.script.DefaultScriptExecutor$1.doInRedis(DefaultScriptExecutor.java:71) 
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:207) 
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:169) 
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:157) 
at org.springframework.data.redis.core.script.DefaultScriptExecutor.execute(DefaultScriptExecutor.java:60) 
at org.springframework.data.redis.core.script.DefaultScriptExecutor.execute(DefaultScriptExecutor.java:54) 
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:300) 

답변

1

전환합니다.

@Bean 
LettuceConnectionFactory redisConnectionFactory(RedisProperties redisProperties) { 

    Cluster clusterProperties = redisProperties.getCluster(); 
    RedisClusterConfiguration config = new RedisClusterConfiguration(
      clusterProperties.getNodes()); 

    if (clusterProperties.getMaxRedirects() != null) { 
     config.setMaxRedirects(clusterProperties.getMaxRedirects()); 
    } 

    return new LettuceConnectionFactory(config); 
} 
+0

감사 :

봄 부팅 1.5.x 이하를위한 구성처럼 보일 수 있습니다. 상추를 이용한 봄 부츠의 예가 있습니까? –

+0

답변을 업데이트했습니다. – mp911de

+0

많은 감사합니다! 잘 작동한다. –