Redis and Spring Integration ·

Source: Internet
Author: User
Tags connection pooling

Configure Spring configuration file applicationcontext.xml

<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:mvc= "Http://www.springframework.org/schema/mvc"Xmlns:context= "Http://www.springframework.org/schema/context"XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"Xmlns:tx= "Http://www.springframework.org/schema/tx"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-3.2.xsd Http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/s Pring-mvc-3.2.xsd Http://www.springframework.org/schema/context Http://www.springframework.org/schema/cont Ext/spring-context-3.2.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP Http://www.springframework.org/schema /aop/spring-aop-3.2.xsd Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/ Spring-tx-3.2.xsd "><!--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 stand-alone through connection pooling -    <BeanID= "Jedispool"class= "Redis.clients.jedis.JedisPool"Destroy-method= "Close">        <Constructor-argname= "Poolconfig"ref= "Jedispoolconfig"/>        <Constructor-argname= "Host"value= "192.168.25.145"/>        <Constructor-argname= "Port"value= "6379"/>    </Bean>

Test:

1 PrivateApplicationContext ApplicationContext;2 3 @Before4      Public voidinit () {5ApplicationContext =NewClasspathxmlapplicationcontext (6"Classpath:applicationContext.xml");7     }8 9 @TestTen      Public voidTestjedispool () { OneJedispool pool = (jedispool) applicationcontext.getbean ("Jedispool"); A             Try  { -Jedis =Pool.getresource (); -              theJedis.set ("name", "Lisi"); -String name = Jedis.get ("name"); - System.out.println (name); -}Catch(Exception ex) { + ex.printstacktrace (); -}finally{ +             if(Jedis! =NULL){ A                 //Close Connection at jedis.close (); -             } -         } -}

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.