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