SPRINGMVC Integrated Redis

Source: Internet
Author: User
Tags redis server

1. Software Environment Springmvc4.1.1.release+redis Server (2.8.19)

2. Add redis.clients based on MAVEN support (latest 2.6.2)

<!--redis-->
<dependency>
<groupid>redis.clients</groupId>
<artifactid>jedis</artifactId>
<version>2.6.2</version>
</dependency>

< Span style= "color: #e8bf6a;" >     <!- -Spring-redis-->
<dependency>
< Groupid>org.springframework.data</GROUPID>
<artifactid>spring-data-redis</artifactid
<version>1.2.1.release</version
</dependency>

3. New Redis configuration file redis.properties

#redis setting
#ip
Redis.ip=127.0.0.1
#port
Redis.port=6379
#密码
Redis.pass= myredis123

#最大能够保持idel状态的对象数
Redis.maxidle=200
#最大分配的对象数
redis.maxtotal =512
#当池内没有返回对象时, Maximum wait time
Redis.maxwaitmillis=1000
#当调用borrow the object method, check for validity
=true

4. Integrate Redis Spring-redis.xml in the spring configuration file

<!--redis resource file--
<Context:p Roperty-placeholderLocation= "Classpath:redis.properties"/>
<beanId= "Poolconfig"Class= "Redis.clients.jedis.JedisPoolConfig">
<propertyName= "Maxidle"Value= "${redis.maxidle}"/>
<propertyName= "Maxtotal"Value= "${redis.maxtotal}"/>
<propertyName= "Maxwaitmillis"Value= "${redis.maxwaitmillis}"/>
<propertyName= "Testonborrow"Value= "${redis.testonborrow}"/>
</bean>
<beanId= "ConnectionFactory"Class= "Org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<propertyName= "HostName"Value= "${redis.ip}"/>
<propertyName= "Port"Value= "${redis.port}"/>
<propertyName= "Password"Value= "${redis.pass}"/>
<property name= " Poolconfig "value=" Poolconfig " />
</BEAN>
<bean id= " Redistemplate "class=" Org.springframework.data.redis.core.StringRedisTemplate ">
<property name= "ConnectionFactory" ref= "ConnectionFactory" />
</bean>

SPRINGMVC Integrated Redis

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.