Клиент принимает последние джедаи 2.7
1. Зависимости:
<Depective> <groupid> redis.clients </GroupId> <ArtifactId> jedis </artifactid> <sersive> 2.7.3 </version> </dependency>
2. Добавить конфигурацию пружины
<bean name = "geneicObjectPoolConfig"> <свойство name = "maxwaitmillis" value = "-1" /> <property name = "maxtotal" value = "1000" /> <name = "minidle" value = "8" /> <name = "maxidle" value = "100" /> < /bean> <bean id = " name="addressConfig"><value>classpath:connect-redis.properties</value></property><property name="addressKeyPrefix" value="address" /> <!-- Prefix of key in the property file --><property name="timeout" value="300000" /><property name="maxRedirections" value="6" /><property name="genericObjectPoolConfig" ref = "geneicObjectPoolConfig" /> < /bean>
3. Добавить файл конфигурации Connect-REDIS.Properties
6 узлов настроены здесь
Address1 =*:*ADDRICE2 =*:*ADDRICE3 =*:*ADDRICE4 =*:*ADDRICE5 =*:*ADDRICE6 =*:*ADDRED6 =*:*
4. Добавить класс Java:
Импорт java.util.hashset; import java.util.properties; import java.util.set; import java.util.regex.pattern; импорт org.apache.commons.pool2.impl.genericobjectpoolconfig; import org.spramework.beans.factory.factorybean; org.springframework.beans.factory.initializebean; import org.springframework.core.io.resource; import redis.clients.jedis.hostandport; import redis.clients.jedis.jediscluster; public class jedisclustery stractorsceansembean wiredsicluster {privationbean restricsecrustersecrustersecrusterseconcepcean. AddressKeyprefix; Private Jediscluster Jediscluster; Private Integer Timeout; Private Integer MaxRidections; Private GenericObjectPoolConfig GenericObjectPoolConfig; Private Pattern P = Pattern.compile ("^.+[:] // d {1,5} // s*$") jediscluster;}@overridepublic class <? extends jediscluster> getObjectType () {return (this.jediscluster! = null? this.jediscluster.getClass (): jediscluster.class);}@overridepublic boolean issingleton () {return true;} private <hostandport> parsehostandport () throws excecate {tress {uspertio Properties (); Prop.Load (this.AddressConfig.getInputStream ()); set <hostandport> hasps = new Hashset <hostandport> (); for (объект ключ: prop.keyset ()) {if (! ((String) Key) .StartSwith (addreskeyprefix)) {} string val = (string) prop.get.getip (addreseypx)) {} string val = (string); p.matcher (val) .matches (); if (! isipport) {throw new allogalargumentException ("IP или порт нелегальный");} string [] ipandport = val.split (":"); hostandport hap = new hostandport (ipandport [0], integer.parseint (ipandport [1]); (OldalalArgumentException ex) {Throw ex;} Catch (Exception Ex) {Throw New Exception ("Parse Jedis Configuration Falie", Ex);}}@overridePublic void efpropertiesset () Throws exception {set <hostandport> hasp = this.parsehostandport (); jedisiscluster = new jediscluster (hasps = this.parsehostandport (); jediscluster = new jediscluster (hasps = this.parsehostandport (); maxRedirections,genericObjectPoolConfig);}public void setAddressConfig(Resource addressConfig) {this.addressConfig = addressConfig;}public void setTimeout(int timeout) {this.timeout = timeout;}public void setMaxRedirections(int maxRedirections) {this.maxRedirections = maxRedirections;}public void setAdDressKeyprefix (string addresskeyprefix) {this.addresskeyprefix = addrykeyprefix;} public void setGenericObjectPoolConfig (geneicObjectPoolConfig genericObjectpoolConfig) {this.genericObjectPOLCONFIG = GenericObjectPOOLCONFIG; 5. Конфигурация завершена на этом этапе
При использовании, просто вводите его напрямую, как показано ниже:
@Autowiredjediscluster jediscluster;
Суммировать
Выше приведено подробное объяснение весенней интеграции Redis Cluster, я надеюсь, что это будет полезно для всех. Если есть какие -либо недостатки, пожалуйста, оставьте сообщение, чтобы указать это. Спасибо, друзья, за вашу поддержку на этом сайте!