使用spring-data-redis操作redis
2016-06-18 18:14
639 查看
redis.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="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" /> <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"> <property name="maxIdle" value="${redis.maxIdle}" /> <property name="maxTotal" value="${redis.maxActive}" /> <property name="maxWaitMillis" value="${redis.maxWait}" /> <property name="testOnBorrow" value="${redis.testOnBorrow}" /> </bean> <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"> <property name="hostName" value="${redis.host}" /> <property name="port" value="${redis.port}" /> <property name="poolConfig" ref="jedisPoolConfig" /> </bean> <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"> <property name="connectionFactory" ref="jedisConnectionFactory" /> <property name="keySerializer"> <bean class="org.springframework.data.redis.serializer.StringRedisSerializer" /> </property> </bean> </beans>
redis.properties
redis.host=127.0.0.1 redis.port=6379 redis.pass= redis.maxIdle=300 redis.maxActive=600 redis.maxWait=1000 redis.testOnBorrow=true
操作User对象的demo
@Resource RedisTemplate<String, User> redisTemplate; public void saveUser(User user){ redisTemplate.opsForValue().set(user.getUserId, user); } public User getUser(String userId){
return redisTemplate.opsForValue().get(userId); }
相关文章推荐
- 关于spring session redis共享session的跨子域的处理
- Redis 相关学习
- redis.conf 配置详解
- Windows7下安装搭建redis教程和配置详解
- Redis安装异常解决办法
- Redis学习(一)
- Redis学习手册
- Redis 分区实现原理
- asp.net core 使用 Redis 和 Protobuf 进行 Session 缓存
- redis入门
- Redis单机、集群环境下配置及模板工具类
- Redis异步化组件模型
- redis 介绍
- Redis入门级指南---客户端命令基本操作
- NoSQL之Redis---PUB/SUB(订阅与发布)---JAVA实现
- spring-data整合redis提供通用接口
- Python的Flask框架使用Redis做数据缓存的配置方法
- tomcat-redis-session管理 使用说明
- tomcat-redis-session管理 使用说明
- CentOS 下安装 Redis