Redis and Spring Integration

Source: Internet
Author: User
Tags redis cluster

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.