Redis.xml
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:context= "Http://www.springframework.org/schema/context"xmlns:p= "Http://www.springframework.org/schema/mvc"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd Http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd "> <Context:property-placeholder Location= "Classpath*:redis.properties" /> <BeanID= "Jedispoolconfig"class= "Redis.clients.jedis.JedisPoolConfig"> < Propertyname= "Maxidle"value= "${redis.maxidle}" /> < Propertyname= "Maxtotal"value= "${redis.maxactive}" /> < Propertyname= "Maxwaitmillis"value= "${redis.maxwait}" /> < Propertyname= "Testonborrow"value= "${redis.testonborrow}" /> </Bean> <BeanID= "Jedisconnectionfactory"class= "Org.springframework.data.redis.connection.jedis.JedisConnectionFactory"> < Propertyname= "HostName"value= "${redis.host}" /> < Propertyname= "Port"value= "${redis.port}" /> < Propertyname= "Poolconfig"ref= "Jedispoolconfig" /> </Bean> <BeanID= "Redistemplate"class= "Org.springframework.data.redis.core.RedisTemplate"> < Propertyname= "ConnectionFactory"ref= "Jedisconnectionfactory" /> < Propertyname= "Keyserializer"> <Beanclass= "Org.springframework.data.redis.serializer.StringRedisSerializer" /> </ Property> </Bean></Beans>
Redis.properties
redis.host=127.0.0.1redis.port=6379redis.pass=redis.maxidle=300redis.maxactive=600redis.maxwait= 1000redis.testonborrow=true
Manipulating the user object's demo
@ResourceRedisTemplate<string, user> redistemplate; Public void saveuser (user user) { redistemplate.opsforvalue (). Set (User.getuserid, user);} Public User GetUser (String userId) {
return Redistemplate.opsforvalue (). get (userId);
Using Spring-data-redis to manipulate Redis