고객은 최신 Jedis 2.7을 채택합니다
1. Maven 의존성 :
<pectionency> <groupid> redis.clients </groupid> <artifactid> jedis </artifactid> <bersion> 2.7.3 </version> </fectionency>
2. 스프링 구성을 추가하십시오
<bean name = "genericobjectpoolconfig"> <property name = "maxwaitmillis"value = "-1" /> <속성 이름 = "maxtotal"value = "1000" /> <property name = "minidle"value = "8" /> <property name = "maxidle"value = "100" /> < /bean> <bean id = "jedis clopters" "<a bean id ="< name = "addressConfig"> <alue> classPath : Connect-Redis.ProperTies < /value> < /property> <속성 이름 = "jusderKeyPREFIX"value = "jesdce" /> <!-속성 파일의 키의 프리픽스-> <속성 이름 = "timeout"value = "300000" /> <property name = "value ="6 " /> <property name" /> ref = "genericobjectpoolconfig" /> < /bean>
3. Connect-Redis.Properties 구성 파일을 추가하십시오
6 개의 노드가 여기에서 구성됩니다
address1 =*:*address2 =*:*address3 =*:*address4 =*:*address5 =*:*address6 =*:*address6 =*:*
4. Java 클래스 추가 :
import java.util.hashset; import java.util.properties; import java.util.set; import java.util.regex.pattern; import org.apache.commons.pool2.impl.genericobjectpoolconfig; import org.springframework.bean.beansory.factorybean; org.springframework.bean.beans.factory.initializingbean; import org.springframework.core.io.resource; import redis.clients.jedis.hostandport; import redis.clients.jedis.jediscluster; public jedisclustory rements factorybean <jedisclust>, {private repiratecclust> 주소는 주소 Jediscluster Jediscluster; 개인 정수 시간 초과; 개인 정수 Maxredipection; 개인 genericobjectpoolconfig genericobjectpoolconfig; private pattern.compile ( "^.+[:] // d {1,5} // s*$"); jediscluster;}@overridepublic class <? jediscluster> getObjectType () {return (this.jediscluster! = null? this.jediscluster.getClass () : jediscluster.class);}@atedreidepublic boolean issingleton () {return true; Properties (); prop.load (this.addressconfig.getInputStream ()); set <hostandport> hasps = new Hashset <hoshsandport> (); for (객체 키 : prop.keyset ()) {if (! (String) key) .StartSwith (string val =} prop.get (key); boolean). p.matcher (val) .matches (); if (! isipport) {새로운 불법 불법 행위 ( "IP 또는 포트는 불법");} 문자열 [] ipandport = val.split ( ":"); hostandport hap = new Hostandport (ipandport [0], integer.pandport [1]); haps.add (haps.); haps;} catch (dishalargumentexception ex) {throw ex;} catch (예외) {throw new exception ( "Parse Jedis 구성 파일 실패", ex)}@atredridepublic void AfterProperTiesset () throws {set <hostandport> hasps = this.parsehostandport (jediscluster); maxRedirections, genericobjectpoolconfig);} public void setAddressconfig (resource jourdhconfig) {this.addressconfig = addressConfig;} public void settimeout (int timeout) {this.timeout;} public void setMax (int maxredirections) {this.maxax avax avax; setAddresskeyPREFIX (String jand 5.이 시점에서 구성이 완료됩니다
사용 중일 때는 아래와 같이 직접 주입하십시오.
@autowiredjediscluster jediscluster;
요약
위의 내용은 스프링 통합 Redis 클러스터에 대한 자세한 설명입니다. 모든 사람에게 도움이되기를 바랍니다. 단점이 있으면 메시지를 남겨 두십시오. 이 사이트를 지원해 주신 친구들에게 감사드립니다!