2018-12-12 18:14
public class RedisCacheAttrBean implements Serializable 在这里序列化了啊@oschina
2018-12-12 16:30
package com.sview.web.redis.utils;
import com.jfinal.plugin.redis.Cache;
import com.jfinal.plugin.redis.Redis;
import com.sview.web.redis.bean.RedisCacheAttrBean;
/**
*
* @category App层使用的Redis缓存工具类
* @author liuy
*/
public class RedisAppUtils {
public static Cache cache = Redis.use("sview_redis");
public static final int EXPIRY_SECONDS = 60*2;
public static final String HEAD = "key_";// 键值前缀,可能会用于搜索
/**
* Redis好像不支持带/,需要把url地址的 "/" 转化成 "_"
* @category admin/index 内容缓存
* @author liuy
*/
public static void setJsonToCache(Object object, String actionKey) {
setRedisExpiry(HEAD + actionKey.replaceAll("/", "_"), object);
}
public static void setAttrToCache(RedisCacheAttrBean request, String actionKey) {
setRedisExpiry(HEAD + actionKey.replaceAll("/", "_"), request);
}
public static RedisCacheAttrBean getAdminIndex(String actionKey) {
return cache.get(HEAD + actionKey.replaceAll("/", "_"));
}
public static Object getObjectByKey(String actionKey) {
return cache.get(HEAD + actionKey.replaceAll("/", "_"));
}
/**
*
* @category 同一配置过期时间为120秒
* @author liuy
*/
private static void setRedisExpiry(String key, Object object) {
cache.setex(key, EXPIRY_SECONDS, object);
}
}
存数据