The use of Redis in the spring framework

Source: Internet
Author: User
Tags redis redis server

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;


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.