Client implementations of Redis I chose Jedis.
The spring framework contains support for Redis, which is actually a layer of encapsulation that allows us to use boilerplate to simplify code or choose not to use the template provided by spring and to encapsulate it on a jedis basis.
Using the spring project makes it easy to add Redis functionality as a system cache
The REDIS server is deployed separately, and the Redis client is configured in spring to allow the spring project to access the Redis servers
The first is the introduction of the package,
<dependency>
<groupId>redis.clients</groupId>
<artifactid>jedis</artifactid >
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId> Spring-data-redis</artifactid>
<version>1.0.2.RELEASE</version>
Part of spring configuration, different Jedis versions, parameters have also changed, especially the need to pay attention to the different versions using the corresponding parameters named
<context:property-placeholder location= "Classpath:redis.properties"/> <context:component-scan Base-package= "Com.x.redis.dao" > </context:component-scan> <bean id= "Poolconfig" class= "REDIS.CLIENTS.J Edis. Jedispoolconfig "> <property name=" maxidle "value=" ${redis.maxidle} "/> <property name=" max Active "value=" ${redis.maxactive} "/> <property name=" maxwait "value=" ${redis.maxwait} "/> &L T;property name= "Testonborrow" value= "${redis.testonborrow}"/> </bean> <bean id= "Connectio Nfactory "class=" Org.springframework.data.redis.connection.jedis.JedisConnectionFactory "P:host-name=" ${redis.ho ST} "p:port=" ${redis.port} "p:password=" ${redis.pass} "p:pool-config-ref=" Poolconfig "/> <bean id=" Redi Stemplate "class=" org.springframework.data.redis.core.StringRedisTemplate "> <property name=" connectionfact Ory "ref=" ConnectionFactory "/> </bean>
Last Bean Redistemplate
Use in a program in a way that is injected
@Autowired
protected redistemplate<serializable, serializable> redistemplate;