Spring Data Redis Use example

Source: Internet
Author: User

1. Configuring Dependent Files

<Dependencies>    <Dependency>        <groupId>Org.springframework.data</groupId>        <Artifactid>Spring-data-redis</Artifactid>        <version>1.5.0.RELEASE</version>    </Dependency></Dependencies>

2. Configure the template

<BeanID= "Jedisconnfactory"class= "Org.springframework.data.redis.connection.jedis.JedisConnectionFactory"P:use-pool= "true"/><!--redis Template Definition -<BeanID= "Redistemplate"class= "Org.springframework.data.redis.core.RedisTemplate"P:connection-factory-ref= "Jedisconnfactory"/>

3. Examples of Use:

3.1 k-v use of string types

Get method:

Redistemplate.opsforvalue (). get (key);

Set Method:

    /**     @param  key     @param  value      @param  Livetime     */    privatevoidlong  livetime) {        Redistemplate.opsforvalue (). Set (key, value, Livetime, timeunit.seconds);    }

3.2 List Type

 Public classExample {//inject the actual template@AutowiredPrivateRedistemplate<string, string>template; //inject the template as Listoperations//can also inject as Value, Set, Zset, and Hashoperations@Resource (name= "Redistemplate")    PrivateListoperations<string, string>Listops;  Public voidAddlink (String userid, url url) {listops.leftpush (userid, Url.toexternalform ()); //or use template directlyredistemplate.boundlistops (userId). Leftpush (Url.toexternalform ()); }}

Similarly, other types can use the

Redistemplate's Opsforx () method

Reference documents:

http://projects.spring.io/spring-data-redis/

Spring Data Redis Use example

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.