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