标签:
<!-- Redis 配置 -->
<bean id="connectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" destroy-method="destroy">
<property name="hostName" value="${redis.host}" />
<property name="port" value="${redis.port}" />
<property name="usePool" value="true" />
</bean>
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="connectionFactory" />
<property name="keySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"></bean>
</property>
<property name="valueSerializer">
<bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer"></bean>
</property>
</bean>
public class RedisDao implements InitializingBean {
@Resource(name="redisTemplate")
protected RedisTemplate<String, Object> redisTemplate;
protected ValueOperations<String, Object> valueOperations = null;
@Override
public void afterPropertiesSet() throws Exception {
valueOperations = redisTemplate.opsForValue();
}
}
@Repository
public class SessionRedisDao extends RedisDao {
public SessionEntity getSession(String sessionId){
return (SessionEntity) valueOperations.get(sessionId);
}
public boolean setSessionEntity(SessionEntity sessionEntity){
valueOperations.set(sessionEntity.getSessionId(), sessionEntity);
return true;
}
public boolean deleteSessionEntity(String sessionId){
if(getSession(sessionId)==null){
return true;
}
redisTemplate.delete(sessionId);
return true;
}
}
标签:
原文地址:http://www.cnblogs.com/sunchuanlei/p/4930489.html