#IP
redis.ip=10.44.218.24
#Port
redis.port=6379
#dbindex
redis.database=0
<!-- 对象池配置 -->
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxActive" value="${redis.pool.maxActive}" />
<property name="maxIdle" value="${redis.pool.maxIdle}" />
<property name="maxWait" value="${redis.pool.maxWait}" />
<property name="testOnBorrow" value="${redis.pool.testOnBorrow}" />
</bean>
<!-- 配置jedisConnFactory -->
<bean id="jedisConnFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="hostName" value="${redis.ip}" />
<property name="port" value="${redis.port}" />
<property name="database" value="${redis.database}" />
<property name="poolConfig" ref="jedisPoolConfig" />
</bean>
public class Webutil {
public static String geneRedisKey(String cid, String attrname) {
String key = RedisKeyPrefix.SYSTEM + keySeparator+ RedisKeyPrefix.LOGIN_SESSION + keySeparator + cid
+ keySeparator + attrname;
return key;
}
/**
* 设置request属性
*
* @param request
* @param attrname
* 属性名称
* @param value
* 属性值<br>
* 调用方式如:Webutil.setRequestAttribute(req,usernam,allen)
*/
public static void setRequestAttribute(HttpServletRequest request,
String attrname, Object value) {
request.setAttribute(attrname, value);
}
/**
* 获取某属性在request中的属性
*
* @param request
* @param attrname
* 属性名称 调用方式如:Webutil.getRequestAttribute(req,usernam)
*/
public static Object getRequestAttribute(HttpServletRequest request,
String attrname) {
if (!"false".equals(useRedis) && useRedis != null) {
return getAttribute(request, attrname);
} else {
return request.getAttribute(attrname);
}
}
/**
* 删除session
*
* @param request
* @param attrname
* 属性名称 调用方式如:Webutil.getRequestAttribute(req,usernam)
*/
public static void removeAttr(String key){
SessionService.getInstance().remove(key);
}
/**
* setAttribute:保存关键字及对应的值,同时设置关键字超时时间. <br/>
*
* @author z1979
* @param key
* 关键字
* @param value
* 值域
* @param timeoutSecends
* 数据超时时间(秒)
* @since JDK 1.7
*/
public static void setAttribute(String key, Object value, long timeoutSecends){
SessionService.getInstance().saveTimeoutTime(key, value,timeoutSecends);
}
public static Object getAttribute(String key) {
return SessionService.getInstance().get(key);
}
}
redis.ip=10.44.218.24
#Port
redis.port=6379
#dbindex
redis.database=0
<!-- 对象池配置 -->
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxActive" value="${redis.pool.maxActive}" />
<property name="maxIdle" value="${redis.pool.maxIdle}" />
<property name="maxWait" value="${redis.pool.maxWait}" />
<property name="testOnBorrow" value="${redis.pool.testOnBorrow}" />
</bean>
<!-- 配置jedisConnFactory -->
<bean id="jedisConnFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="hostName" value="${redis.ip}" />
<property name="port" value="${redis.port}" />
<property name="database" value="${redis.database}" />
<property name="poolConfig" ref="jedisPoolConfig" />
</bean>
public class Webutil {
public static String geneRedisKey(String cid, String attrname) {
String key = RedisKeyPrefix.SYSTEM + keySeparator+ RedisKeyPrefix.LOGIN_SESSION + keySeparator + cid
+ keySeparator + attrname;
return key;
}
/**
* 设置request属性
*
* @param request
* @param attrname
* 属性名称
* @param value
* 属性值<br>
* 调用方式如:Webutil.setRequestAttribute(req,usernam,allen)
*/
public static void setRequestAttribute(HttpServletRequest request,
String attrname, Object value) {
request.setAttribute(attrname, value);
}
/**
* 获取某属性在request中的属性
*
* @param request
* @param attrname
* 属性名称 调用方式如:Webutil.getRequestAttribute(req,usernam)
*/
public static Object getRequestAttribute(HttpServletRequest request,
String attrname) {
if (!"false".equals(useRedis) && useRedis != null) {
return getAttribute(request, attrname);
} else {
return request.getAttribute(attrname);
}
}
/**
* 删除session
*
* @param request
* @param attrname
* 属性名称 调用方式如:Webutil.getRequestAttribute(req,usernam)
*/
public static void removeAttr(String key){
SessionService.getInstance().remove(key);
}
/**
* setAttribute:保存关键字及对应的值,同时设置关键字超时时间. <br/>
*
* @author z1979
* @param key
* 关键字
* @param value
* 值域
* @param timeoutSecends
* 数据超时时间(秒)
* @since JDK 1.7
*/
public static void setAttribute(String key, Object value, long timeoutSecends){
SessionService.getInstance().saveTimeoutTime(key, value,timeoutSecends);
}
public static Object getAttribute(String key) {
return SessionService.getInstance().get(key);
}
}