Spring Data Redis Consolidation

Source: Internet
Author: User
Tags connection pooling

  

First of all, now the Redis package, the official website is http://redis.io/download

Once downloaded, unzip the Redis tarball directly to the specified directory:

    

    

Use the corresponding number of digits in the operating system folder under the Redis-server.exe command to start redis (Test command redis-server.exe service launcher redis-cli.exe client command-line tool the redis.conf service profile starts the service through Redis-server.exe, and the default port 6379 through Redis-cli.exe Start the Client tool ).

  

1. In the program, with the MAVEN coordinates, the spring data Redis is introduced, and the commands are as follows:

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.4.1.RELEASE</version>
</dependency>

2. Configure the Applicationcontext.xml code as follows:

<!-- Configure redis connection pooling --

<bean id= "Poolconfig" class= "Redis.clients.jedis.JedisPoolConfig" >

<property name= "Maxidle" value= "/>"

<property name= "Maxwaitmillis" value= "/>"

<property name= "Testonborrow" value= "true"/>

</bean>

<!-- configuration consolidation Jedis factory connection Pool --

<bean id= "Redisconnectionfactory" class= " Org.springframework.data.redis.connection.jedis.JedisConnectionFactory ">

<property name= "hostName" value= "localhost"/>

<property name= "Port" value= "6379"/>

<property name= "Poolconfig" ref= "Poolconfig"/>

</bean>

<!-- Configuration integrates redis templates --

<bean id= "Redistemplate" class= "Org.springframework.data.redis.core.RedisTemplate" >

<property name= "ConnectionFactory" ref= "Redisconnectionfactory"/>

<property name= "Keyserializer" >

<bean class= "Org.springframework.data.redis.serializer.StringRedisSerializer"/>

</property>

<property name= "ValueSerializer" >

<bean class= "Org.springframework.data.redis.serializer.StringRedisSerializer"/>

</property>

</bean>

3. Write the test code as follows:

@RunWith (Springjunit4classrunner.class)
@ContextConfiguration ("Classpath:applicationContext.xml")
public class Springdataredis {
@Resource
Private redistemplate<string,string> redistemplate;
@Test
public void Testredis () {
Redistemplate.opsforvalue (). Set ("TestKey", "Mytestvaule", 1, timeunit.days);
}
}

The first time to write a blog there are many shortcomings please big guys forgive Yo!

Spring Data Redis Consolidation

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.