Configure Applicationcontext.xml
<!--Connection Pool Configuration - <BeanID= "Jedispoolconfig"class= "Redis.clients.jedis.JedisPoolConfig"> <!--Maximum number of connections - < Propertyname= "Maxtotal"value= "+" /> <!--Maximum number of idle connections - < Propertyname= "Maxidle"value= "Ten" /> <!--maximum number of connections per release - < Propertyname= "Numtestsperevictionrun"value= "1024x768" /> <!--scan interval for free connections (MS) - < Propertyname= "Timebetweenevictionrunsmillis"value= "30000" /> <!--Connect minimum idle time - < Propertyname= "Minevictableidletimemillis"value= "1800000" /> <!--How long the connection is free and released when idle time > This value and free connections > maximum idle connections are released directly - < Propertyname= "Softminevictableidletimemillis"value= "10000" /> <!--maximum wait milliseconds to get a connection, less than 0: blocking indeterminate time, default-1 - < Propertyname= "Maxwaitmillis"value= " the" /> <!--check validity when getting a connection, default false - < Propertyname= "Testonborrow"value= "true" /> <!--check validity on idle, default false - < Propertyname= "Testwhileidle"value= "true" /> <!--If the connection is exhausted, false to report an exception, ture block until timeout, default true - < Propertyname= "blockwhenexhausted"value= "false" /> </Bean> <!--Redis Cluster - <BeanID= "Jediscluster"class= "Redis.clients.jedis.JedisCluster"> <Constructor-argIndex= "0"> <Set> <Beanclass= "Redis.clients.jedis.HostAndPort"> <Constructor-argIndex= "0"value= "192.168.101.3"></Constructor-arg> <Constructor-argIndex= "1"value= "7001"></Constructor-arg> </Bean> <Beanclass= "Redis.clients.jedis.HostAndPort"> <Constructor-argIndex= "0"value= "192.168.101.3"></Constructor-arg> <Constructor-argIndex= "1"value= "7002"></Constructor-arg> </Bean> <Beanclass= "Redis.clients.jedis.HostAndPort"> <Constructor-argIndex= "0"value= "192.168.101.3"></Constructor-arg> <Constructor-argIndex= "1"value= "7003"></Constructor-arg> </Bean> <Beanclass= "Redis.clients.jedis.HostAndPort"> <Constructor-argIndex= "0"value= "192.168.101.3"></Constructor-arg> <Constructor-argIndex= "1"value= "7004"></Constructor-arg> </Bean> <Beanclass= "Redis.clients.jedis.HostAndPort"> <Constructor-argIndex= "0"value= "192.168.101.3"></Constructor-arg> <Constructor-argIndex= "1"value= "7005"></Constructor-arg> </Bean> <Beanclass= "Redis.clients.jedis.HostAndPort"> <Constructor-argIndex= "0"value= "192.168.101.3"></Constructor-arg> <Constructor-argIndex= "1"value= "7006"></Constructor-arg> </Bean> </Set> </Constructor-arg> <Constructor-argIndex= "1"ref= "Jedispoolconfig"></Constructor-arg> </Bean>
Test code
PrivateApplicationContext ApplicationContext; @Before Public voidinit () {ApplicationContext=NewClasspathxmlapplicationcontext ("Classpath:applicationContext.xml"); } //Redis Cluster@Test Public voidTestjediscluster () {jediscluster jediscluster=(Jediscluster) applicationcontext. Getbean ("Jediscluster"); Jediscluster.set ("Name", "Zhangsan"); String value= Jediscluster.get ("name"); System.out.println (value); }
Redis and Spring Integration