Commit 3b48cfc7 by gaopeng

modify 更新主干代码

parent edadc760
...@@ -84,4 +84,6 @@ liveRunEnvironment = prod_ ...@@ -84,4 +84,6 @@ liveRunEnvironment = prod_
uedThirdPartyOrderUrl=https://rayscloud.chubanyun.net uedThirdPartyOrderUrl=https://rayscloud.chubanyun.net
## \u7CFB\u7EDF\u73AF\u5883 ## \u7CFB\u7EDF\u73AF\u5883
system.env = pro system.env = pro
\ No newline at end of file
jsbj.agent.id = 1000009100
\ No newline at end of file
...@@ -86,4 +86,6 @@ liveRunEnvironment = uat_ ...@@ -86,4 +86,6 @@ liveRunEnvironment = uat_
uedThirdPartyOrderUrl=http://deveapi.chubanyun.net uedThirdPartyOrderUrl=http://deveapi.chubanyun.net
## \u7CFB\u7EDF\u73AF\u5883 ## \u7CFB\u7EDF\u73AF\u5883
system.env = uat system.env = uat
\ No newline at end of file
jsbj.agent.id = 12829
\ No newline at end of file
...@@ -51,6 +51,7 @@ public class ParamLogAspect { ...@@ -51,6 +51,7 @@ public class ParamLogAspect {
Signature signature = joinPoint.getSignature(); Signature signature = joinPoint.getSignature();
String methodName = signature.getName(); String methodName = signature.getName();
String description = paramLog.description(); String description = paramLog.description();
description = StringUtil.isEmpty(description) ? paramLog.value() : description;
StringBuffer msg = new StringBuffer("【" + methodName + " before】"); StringBuffer msg = new StringBuffer("【" + methodName + " before】");
if (StringUtil.isEmpty(description)) { if (StringUtil.isEmpty(description)) {
msg.append(joinPoint.getSignature().toString()); msg.append(joinPoint.getSignature().toString());
...@@ -79,6 +80,7 @@ public class ParamLogAspect { ...@@ -79,6 +80,7 @@ public class ParamLogAspect {
Signature signature = joinPoint.getSignature(); Signature signature = joinPoint.getSignature();
String methodName = signature.getName(); String methodName = signature.getName();
String description = paramLog.description(); String description = paramLog.description();
description = StringUtil.isEmpty(description) ? paramLog.value() : description;
StringBuffer msg = new StringBuffer("【" + methodName + " afterReturn】"); StringBuffer msg = new StringBuffer("【" + methodName + " afterReturn】");
if (StringUtil.isEmpty(description)) { if (StringUtil.isEmpty(description)) {
msg.append(joinPoint.getSignature().toString()); msg.append(joinPoint.getSignature().toString());
......
...@@ -70,6 +70,11 @@ public enum AppTypeEnum { ...@@ -70,6 +70,11 @@ public enum AppTypeEnum {
TB("tb"), TB("tb"),
/** /**
* 直播
*/
LIVE("live"),
/**
* 打卡 * 打卡
*/ */
CLOCK("clock"); CLOCK("clock");
......
package com.pcloud.common.core.dto; package com.pcloud.common.core.dto;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/** /**
* 事件埋点 * 事件埋点
*
* @author 石纯山 * @author 石纯山
* @date 2018/4/16 * @date 2018/4/16
*/ */
public class FrontEventDto implements Serializable { public class FrontEventDto implements Serializable {
/** private static final long serialVersionUID = 7668311875701119389L;
* /**
*/ * 事件id
private static final long serialVersionUID = 3065716090982449711L; */
/** private String eventId;
* 事件id /**
*/ * 漏斗id,当为漏斗事件时
private String eventId; */
/** private String funnelId;
* 漏斗id,当为漏斗事件时
*/ /**
private String funnelId; * 事件id集合
*/
/** private Map<String,String> eventMap;
* 编辑id
*/ /**
private Long adviserId; * 编辑id
/** */
* 渠道id private Long adviserId;
*/ /**
private Long channelId; * 渠道id
*/
/** private Long channelId;
* 来源类型0 后端,1 h5,2 小程序,3 app
*/ /**
private short sourceType; * 来源类型0 后端,1 h5,2 小程序,3 app
*/
/** private short sourceType;
* 触发时间
*/ /**
private Long timestamp; * 触发时间
/** */
* 1:RAYS private Long timestamp;
*/ /**
private String platCode; * 1:RAYS
/** */
* 0:不是读者,1:读者 private String platCode;
*/ /**
private short isReader; * 0:不是读者,1:读者
/** */
* 当事人id private short isReader;
*/ /**
private Long partyId; * 当事人id
/** */
* 用户角色编码 private Long partyId;
*/ /**
private String systemCode; * 用户角色编码
*/
/** private String systemCode;
* 读者所在的公众号
*/ /**
private Long officeAccountId; * 读者所在的公众号
/** */
* 平台读者id private Long officeAccountId;
*/ /**
private Long wechatUserId; * 平台读者id
*/
/** private Long wechatUserId;
* 场景id
*/ /**
private Long sceneId; * 场景id
/** */
* 出版id private Long sceneId;
*/ /**
private Long agentId; * 出版id
*/
private String Exp1; private Long agentId;
private String Exp2;
private String Exp3; private String Exp1;
private String Exp2;
public String getEventId() { private String Exp3;
return eventId;
} public String getEventId() {
return eventId;
public void setEventId(String eventId) { }
this.eventId = eventId;
} public void setEventId(String eventId) {
this.eventId = eventId;
public String getFunnelId() { }
return funnelId;
} public String getFunnelId() {
return funnelId;
public void setFunnelId(String funnelId) { }
this.funnelId = funnelId;
} public void setFunnelId(String funnelId) {
this.funnelId = funnelId;
public Long getAdviserId() { }
return adviserId;
} public Long getAdviserId() {
return adviserId;
public void setAdviserId(Long adviserId) { }
this.adviserId = adviserId;
} public void setAdviserId(Long adviserId) {
this.adviserId = adviserId;
public Long getChannelId() { }
return channelId;
} public Long getChannelId() {
return channelId;
public void setChannelId(Long channelId) { }
this.channelId = channelId;
} public void setChannelId(Long channelId) {
this.channelId = channelId;
public short getSourceType() { }
return sourceType;
} public short getSourceType() {
return sourceType;
public void setSourceType(short sourceType) { }
this.sourceType = sourceType;
} public void setSourceType(short sourceType) {
this.sourceType = sourceType;
public Long getTimestamp() { }
return timestamp;
} public Long getTimestamp() {
return timestamp;
public void setTimestamp(Long timestamp) { }
this.timestamp = timestamp;
} public void setTimestamp(Long timestamp) {
this.timestamp = timestamp;
public String getPlatCode() { }
return platCode;
} public String getPlatCode() {
return platCode;
public void setPlatCode(String platCode) { }
this.platCode = platCode;
} public void setPlatCode(String platCode) {
this.platCode = platCode;
public short getIsReader() { }
return isReader;
} public short getIsReader() {
return isReader;
public void setIsReader(short isReader) { }
this.isReader = isReader;
} public void setIsReader(short isReader) {
this.isReader = isReader;
public Long getOfficeAccountId() { }
return officeAccountId;
} public Long getOfficeAccountId() {
return officeAccountId;
public void setOfficeAccountId(Long officeAccountId) { }
this.officeAccountId = officeAccountId;
} public void setOfficeAccountId(Long officeAccountId) {
this.officeAccountId = officeAccountId;
public Long getWechatUserId() { }
return wechatUserId;
} public Long getWechatUserId() {
return wechatUserId;
public void setWechatUserId(Long wechatUserId) { }
this.wechatUserId = wechatUserId;
} public void setWechatUserId(Long wechatUserId) {
this.wechatUserId = wechatUserId;
public Long getSceneId() { }
return sceneId;
} public Long getSceneId() {
return sceneId;
public void setSceneId(Long sceneId) { }
this.sceneId = sceneId;
} public void setSceneId(Long sceneId) {
this.sceneId = sceneId;
public Long getAgentId() { }
return agentId;
} public Long getAgentId() {
return agentId;
public void setAgentId(Long agentId) { }
this.agentId = agentId;
} public void setAgentId(Long agentId) {
this.agentId = agentId;
public String getExp1() { }
return Exp1;
} public String getExp1() {
return Exp1;
public void setExp1(String exp1) { }
Exp1 = exp1;
} public void setExp1(String exp1) {
Exp1 = exp1;
public String getExp2() { }
return Exp2;
} public String getExp2() {
return Exp2;
public void setExp2(String exp2) { }
Exp2 = exp2;
} public void setExp2(String exp2) {
Exp2 = exp2;
public String getExp3() { }
return Exp3;
} public String getExp3() {
return Exp3;
public void setExp3(String exp3) { }
Exp3 = exp3;
} public void setExp3(String exp3) {
Exp3 = exp3;
public Long getPartyId() { }
return partyId;
} public Long getPartyId() {
return partyId;
public void setPartyId(Long partyId) { }
this.partyId = partyId;
} public void setPartyId(Long partyId) {
this.partyId = partyId;
public String getSystemCode() { }
return systemCode;
} public String getSystemCode() {
return systemCode;
public void setSystemCode(String systemCode) { }
this.systemCode = systemCode;
} public void setSystemCode(String systemCode) {
this.systemCode = systemCode;
@Override }
public String toString() {
return "PaymentEventDto{" + "eventId='" + eventId + '\'' + ", funnelId='" + funnelId + '\'' + ", adviserId=" public Map<String, String> getEventMap() {
+ adviserId + ", channelId=" + channelId + ", sourceType=" + sourceType + ", timestamp=" + timestamp return eventMap;
+ ", platCode='" + platCode + '\'' + ", isReader=" + isReader + ", partyId=" + partyId }
+ ", systemCode='" + systemCode + '\'' + ", officeAccountId=" + officeAccountId + ", wechatUserId="
+ wechatUserId + ", sceneId=" + sceneId + ", agentId=" + agentId + ", Exp1='" + Exp1 + '\'' + ", Exp2='" public void setEventMap(Map<String, String> eventMap) {
+ Exp2 + '\'' + ", Exp3='" + Exp3 + '\'' + '}'; this.eventMap = eventMap;
} }
public void setEventMap(String eventId, String funnelId) {
if(eventMap == null){
eventMap = new HashMap<>();
}
eventMap.put(eventId,funnelId);
}
@Override
public String toString() {
return "FrontEventDto{" +
"eventId='" + eventId + '\'' +
", funnelId='" + funnelId + '\'' +
", eventMap=" + eventMap +
", adviserId=" + adviserId +
", channelId=" + channelId +
", sourceType=" + sourceType +
", timestamp=" + timestamp +
", platCode='" + platCode + '\'' +
", isReader=" + isReader +
", partyId=" + partyId +
", systemCode='" + systemCode + '\'' +
", officeAccountId=" + officeAccountId +
", wechatUserId=" + wechatUserId +
", sceneId=" + sceneId +
", agentId=" + agentId +
", Exp1='" + Exp1 + '\'' +
", Exp2='" + Exp2 + '\'' +
", Exp3='" + Exp3 + '\'' +
'}';
}
} }
/**
*
*/
package com.pcloud.common.enums; package com.pcloud.common.enums;
import com.google.common.collect.Maps;
import java.util.Arrays;
import java.util.Map;
/** /**
* @描述:应用类型常量枚举 * @描述:应用类型常量枚举
* @作者:songx * @作者:songx
...@@ -10,55 +12,66 @@ package com.pcloud.common.enums; ...@@ -10,55 +12,66 @@ package com.pcloud.common.enums;
*/ */
public enum AppTypeEnum { public enum AppTypeEnum {
MASTER("MASTER"), // 主应用 MASTER("MASTER"), // 主应用
RECOMMEND("RECOMMEND"), // 推荐应用 RECOMMEND("RECOMMEND"), // 推荐应用
CHARGE("CHARGE"), // 付费应用 CHARGE("CHARGE"), // 付费应用
ARTICLE("ARTICLE"), // 文章
KK("KK"), // 看一看
LIVE("LIVE"), // 直播
VOTE("VOTE"), // 投票
ENROLL("ENROLL"), // 编创赛报名
BM("BM"), // 报名
NAIRE("NAIRE"), // 问卷调查
DA("DA"), // 数据采集
BOOKCARD("BOOKCARD"), // 读书卡片
TUTOR("TUTOR"), // 一对一辅导
GROUP("GROUP"), // 与你同行(圈子)(add by gaop at 2017-6-13 16:52:07)
ITEM_BANK("ITEM_BANK"), // 题库
VOICE_MSG("VOICE_MSG"), // 语音留言
AUDIO("AUDIO"), // 音频
VIDEO("VIDEO"), // 视频
IMAGE("IMAGE"), // 图片
PDF("PDF"), // PDF
BOOK("BOOK"), // 图书
EF("EF"), // 教育表格
QA("QA"), // 问答
LISTEN("LISTEN"), // 听力
ANSWER("ANSWER"), // 答案
ACTIVITY("ACTIVITY"), // 分享互动
ZSCORE("ZSCORE"), // 标准分
RECITE_WORD("RECITE_WORD"), // 背单词
INTERACT("INTERACT"), // 互动墙
SPECIAL("SPECIAL"), // 专题
CLOCK("CLOCK"), // 打卡
TEST("TEST"), // 测试
LIVE_TIMETABLE("LIVE_TIMETABLE"), // 直播课表
DRAW("DRAW"), // 抽奖
WISH("WISH"); // 愿望单
/**
* 枚举转换
*/
public static final Map<String, AppTypeEnum> APP_TYPE_MAP = Maps.newHashMap();
ARTICLE("ARTICLE"), // 文章 static {
KK("KK"), // 看一看 Arrays.asList(AppTypeEnum.values()).forEach(m -> {
LIVE("LIVE"), // 直播 APP_TYPE_MAP.put(m.value, m);
VOTE("VOTE"), // 投票 });
ENROLL("ENROLL"), // 编创赛报名 }
BM("BM"), // 报名
NAIRE("NAIRE"), // 问卷调查
DA("DA"), // 数据采集
BOOKCARD("BOOKCARD"), // 读书卡片
TUTOR("TUTOR"), // 一对一辅导
GROUP("GROUP"), // 与你同行(圈子)(add by gaop at 2017-6-13 16:52:07)
ITEM_BANK("ITEM_BANK"), // 题库
VOICE_MSG("VOICE_MSG"), // 语音留言
AUDIO("AUDIO"), // 音频
VIDEO("VIDEO"), // 视频
IMAGE("IMAGE"), // 图片
PDF("PDF"), // PDF
BOOK("BOOK"), // 图书
EF("EF"), // 教育表格
QA("QA"), // 问答
LISTEN("LISTEN"), // 听力
ANSWER("ANSWER"), // 答案
ACTIVITY("ACTIVITY"), // 分享互动
ZSCORE("ZSCORE"), // 标准分
RECITE_WORD("RECITE_WORD"), // 背单词
INTERACT("INTERACT"), // 互动墙
SPECIAL("SPECIAL"), // 专题
CLOCK("CLOCK"), // 打卡
TEST("TEST"), // 测试
LIVE_TIMETABLE("LIVE_TIMETABLE"), // 直播课表
DRAW("DRAW"), // 抽奖
WISH("WISH"); // 愿望单
/** /**
* 值 * 值
*/ */
public final String value; public final String value;
/** /**
* 构造 * 构造
* *
* @param value * @param value
*/ */
private AppTypeEnum(String value) { private AppTypeEnum(String value) {
this.value = value; this.value = value;
} }
} }
package com.pcloud.common.utils;
import org.springframework.beans.BeanUtils;
/**
*
*
* @author:songx
* @date:2018年8月24日,下午2:18:40
*/
public class BeanNewUtils {
/**
* 实体类之间的转换
*
* @param source
* 来源
* @param clazz
* 目标对象
* @return
*/
public static <T> T copyProperties(Object source, T t) {
if (source == null || t == null) {
return t;
}
BeanUtils.copyProperties(source, t);
return t;
}
}
...@@ -6,6 +6,7 @@ import java.text.SimpleDateFormat; ...@@ -6,6 +6,7 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List; import java.util.List;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -1603,4 +1604,78 @@ public class DateUtils extends org.apache.commons.lang.time.DateUtils { ...@@ -1603,4 +1604,78 @@ public class DateUtils extends org.apache.commons.lang.time.DateUtils {
return calendar.getTime(); return calendar.getTime();
} }
/**
* 获取今天开始时间
* @return
*/
public static Date getDayBegin() {
Calendar cal = new GregorianCalendar();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}
/**
* 获取今天结束时间
* @return
*/
public static Date getDayEnd() {
Calendar cal = new GregorianCalendar();
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.MINUTE, 59);
cal.set(Calendar.SECOND, 59);
return cal.getTime();
}
/**
* 获取某个日期的开始时间
* @param day
* @return
*/
public static Timestamp getDayStartTime(Date day) {
Calendar calendar = Calendar.getInstance();
if (null != day) calendar.setTime(day);
calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
calendar.set(Calendar.MILLISECOND, 0);
return new Timestamp(calendar.getTimeInMillis());
}
/**
* 获取某个日期的结束时间
* @param day 日期
* @return
*/
public static Timestamp getDayEndTime(Date day) {
Calendar calendar = Calendar.getInstance();
if (null != day) calendar.setTime(day);
calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), 23, 59, 59);
calendar.set(Calendar.MILLISECOND, 999);
return new Timestamp(calendar.getTimeInMillis());
}
/**
* 获取昨天开始时间
*
* @return
*/
public static Date getBeginDayOfYesterday() {
Calendar cal = new GregorianCalendar();
cal.setTime(getDayBegin());
cal.add(Calendar.DAY_OF_MONTH, -1);
return cal.getTime();
}
/**
* 获取昨天的结束时间
* @return
*/
public static Date getEndDayOfYesterDay() {
Calendar cal = new GregorianCalendar();
cal.setTime(getDayEnd());
cal.add(Calendar.DAY_OF_MONTH, -1);
return cal.getTime();
}
} }
/** /**
* *
*/ */
package com.pcloud.common.utils.cache.redis; package com.pcloud.common.utils.cache.redis;
...@@ -8,6 +8,7 @@ import java.util.List; ...@@ -8,6 +8,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -19,6 +20,7 @@ import com.google.common.collect.Maps; ...@@ -19,6 +20,7 @@ import com.google.common.collect.Maps;
import com.pcloud.common.utils.ListUtils; import com.pcloud.common.utils.ListUtils;
import com.pcloud.common.utils.string.StringUtil; import com.pcloud.common.utils.string.StringUtil;
import org.springframework.util.CollectionUtils;
import redis.clients.jedis.JedisCluster; import redis.clients.jedis.JedisCluster;
/** /**
...@@ -30,1322 +32,1374 @@ import redis.clients.jedis.JedisCluster; ...@@ -30,1322 +32,1374 @@ import redis.clients.jedis.JedisCluster;
@Component("jedisClusterUtils") @Component("jedisClusterUtils")
public class JedisClusterUtils { public class JedisClusterUtils {
/** /**
* *
*/ */
private static Logger LOGGER = LoggerFactory.getLogger(JedisClusterUtils.class); private static Logger LOGGER = LoggerFactory.getLogger(JedisClusterUtils.class);
/** /**
* 默认过期时间(2小时) * 默认过期时间(2小时)
*/ */
private static final Integer REDIS_SESSION_TIMEOUT = 2 * 60 * 60; private static final Integer REDIS_SESSION_TIMEOUT = 2 * 60 * 60;
private static JedisCluster jedisCluster; private static JedisCluster jedisCluster;
/** /**
* 保存一个字符串到redis中,长期有效 * 保存一个字符串到redis中,长期有效
* *
* @param key * @param key 键
* 键 * @param value 值
* @param value * @return
* 值 */
* @return public static boolean set(String key, String value) {
*/ try {
public static boolean set(String key, String value) { jedisCluster.set(key, value);
try { } catch (Exception e) {
jedisCluster.set(key, value); LOGGER.warn("jedis缓存保存失败:" + e.getMessage(), e);
} catch (Exception e) { return false;
LOGGER.warn("jedis缓存保存失败:" + e.getMessage(), e); }
return false; return true;
} }
return true;
} /**
* 根据前缀匹配模糊删除
/** *
* 保存一个字符串到redis中并指定过期时间 * @param fuzzyKey 模糊前缀
* * @return 删除的数量
* @param key */
* 键 public static int fuzzyDel(String fuzzyKey) {
* @param value if (StringUtils.isBlank(fuzzyKey)) {
* 值 return 0;
* @param seconds }
* 有效时间,为null使用默认时间30分钟 Set<String> keys = jedisCluster.hkeys(fuzzyKey);
* @return if (CollectionUtils.isEmpty(keys)) {
*/ return 0;
public static boolean set(String key, String value, Integer seconds) { }
try { int num = 0;
jedisCluster.set(key, value); for (String key : keys) {
expire(key, seconds); if (del(key)) {
} catch (Exception e) { num++;
LOGGER.warn("jedis缓存保存失败:" + e.getMessage(), e); }
return false; }
} return num;
return true; }
}
/**
/** * 保存一个字符串到redis中,长期有效
* 保存一个字符串到redis中,长期有效 *
* * @param key 键
* @param objecKey * @param value 值
* 键 * @return
* @param objecValue */
* 缓存对象 public static boolean getSet(String key, String value) {
* @return try {
*/ jedisCluster.getSet(key, value);
public static boolean setObject(Object key, Object value) { } catch (Exception e) {
try { LOGGER.warn("jedis缓存保存失败:" + e.getMessage(), e);
jedisCluster.set(SerializeUtils.serialize(key), SerializeUtils.serialize(value)); return false;
} catch (Exception e) { }
LOGGER.warn("jedis缓存保存失败:" + e.getMessage(), e); return true;
return false; }
}
return true; public static String getSetR(String key,String value){
} String set;
try {
/** set = jedisCluster.getSet(key, value);
* 保存一个字符串到redis中并指定过期时间 } catch (Exception e) {
* LOGGER.warn("jedis缓存保存失败:" + e.getMessage(), e);
* @param objecKey return null;
* 键 }
* @param objecValue return set;
* 缓存对象 }
* @param seconds
* 时间,如果为null,则使用默认时间30分钟 /**
* @return * 保存一个字符串到redis中并指定过期时间
*/ *
public static boolean setObject(Object key, Object value, Integer seconds) { * @param key 键
if (key == null || value == null) { * @param value 值
return false; * @param seconds 有效时间,为null使用默认时间30分钟
} * @return 旧值
try { */
jedisCluster.set(SerializeUtils.serialize(key), SerializeUtils.serialize(value)); public static String getSet(String key, String value, Integer seconds) {
expireObject(key, seconds); String set;
} catch (Exception e) { try {
LOGGER.warn("jedis缓存保存失败:" + e.getMessage(), e); set = jedisCluster.getSet(key, value);
return false; expire(key, seconds);
} } catch (Exception e) {
return true; LOGGER.warn("jedis getSet缓存保存失败:" + e.getMessage(), e);
} return null;
}
/** return set;
* 当键在redis中不存在时才设置 }
*
* @param key /**
* @param value * 保存一个字符串到redis中并指定过期时间
* @return *
*/ * @param key 键
public static boolean setnx(String key, String value) { * @param value 值
long result = 0; * @param seconds 有效时间,为null使用默认时间30分钟
try { * @return
result = jedisCluster.setnx(key, value); */
} catch (Exception e) { public static boolean set(String key, String value, Integer seconds) {
LOGGER.warn("jedis Setn缓存保存失败:" + e.getMessage(), e); try {
return false; jedisCluster.set(key, value);
} expire(key, seconds);
return result == 0 ? false : true; } catch (Exception e) {
} LOGGER.warn("jedis缓存保存失败:" + e.getMessage(), e);
return false;
/** }
* 追加一个字符串到指定的key return true;
* }
* @param key
* @param value /**
* @return * 保存一个字符串到redis中,长期有效
*/ *
public static boolean append(String key, String value) { * @param objecKey 键
try { * @param objecValue 缓存对象
jedisCluster.append(key, value); * @return
} catch (Exception e) { */
LOGGER.warn("jedis缓存保存失败:" + e.getMessage(), e); public static boolean setObject(Object key, Object value) {
return false; try {
} jedisCluster.set(SerializeUtils.serialize(key), SerializeUtils.serialize(value));
return true; } catch (Exception e) {
} LOGGER.warn("jedis缓存保存失败:" + e.getMessage(), e);
return false;
/** }
* 根据缓存键获取Redis缓存中的值.<br/> return true;
* }
* @param key
* 键 /**
* @return * 保存一个字符串到redis中并指定过期时间
*/ *
public static String get(String key) { * @param objecKey 键
try { * @param objecValue 缓存对象
return jedisCluster.get(key); * @param seconds 时间,如果为null,则使用默认时间30分钟
} catch (Exception e) { * @return
LOGGER.warn("jedis获取缓存失败:" + e.getMessage(), e); */
return null; public static boolean setObject(Object key, Object value, Integer seconds) {
} if (key == null || value == null) {
} return false;
}
/** try {
* 根据缓存键获取Redis缓存中的对象.<br/> jedisCluster.set(SerializeUtils.serialize(key), SerializeUtils.serialize(value));
* expireObject(key, seconds);
* @param objecKey } catch (Exception e) {
* 键 LOGGER.warn("jedis缓存保存失败:" + e.getMessage(), e);
* @return return false;
*/ }
public static Object getObject(Object key) { return true;
try { }
byte[] bytes = jedisCluster.get(SerializeUtils.serialize(key));
return bytes == null ? null : SerializeUtils.unSerialize(bytes); /**
} catch (Exception e) { * 当键在redis中不存在时才设置
LOGGER.warn("jedis获取缓存失败:" + e.getMessage(), e); *
} * @param key
return null; * @param value
} * @return
*/
/** public static boolean setnx(String key, String value) {
* 根据缓存键清除Redis缓存中的对象. long result = 0;
* try {
* @param key result = jedisCluster.setnx(key, value);
* @return } catch (Exception e) {
*/ LOGGER.warn("jedis Setn缓存保存失败:" + e.getMessage(), e);
public static boolean delObject(Object key) { return false;
try { }
jedisCluster.del(SerializeUtils.serialize(key)); return result == 0 ? false : true;
} catch (Exception e) { }
LOGGER.warn("jedis删除缓存失败:" + e.getMessage(), e);
return false; /**
} * 追加一个字符串到指定的key
return true; *
} * @param key
* @param value
/** * @return
* 根据缓存键批量清除Redis缓存中的对象. */
* public static boolean append(String key, String value) {
* @param keys try {
* @return jedisCluster.append(key, value);
*/ } catch (Exception e) {
public static boolean delObject(Object... keys) { LOGGER.warn("jedis缓存保存失败:" + e.getMessage(), e);
try { return false;
jedisCluster.del(SerializeUtils.serialize(keys)); }
} catch (Exception e) { return true;
LOGGER.warn("jedis批量删除缓存失败:" + e.getMessage(), e); }
return false;
} /**
return true; * 根据缓存键获取Redis缓存中的值.<br/>
} *
* @param key 键
/** * @return
* 根据缓存键删除Redis缓存中的值. */
* public static String get(String key) {
* @param key try {
* @return return jedisCluster.get(key);
*/ } catch (Exception e) {
public static boolean del(String key) { LOGGER.warn("jedis获取缓存失败:" + e.getMessage(), e);
try { return null;
jedisCluster.del(key); }
} catch (Exception e) { }
LOGGER.warn("jedis删除缓存失败:" + e.getMessage(), e);
return false; /**
} * 根据缓存键获取Redis缓存中的对象.<br/>
return true; *
} * @param objecKey 键
* @return
/** */
* 根据缓存键批量清除Redis缓存中的值. public static Object getObject(Object key) {
* try {
* @param keys byte[] bytes = jedisCluster.get(SerializeUtils.serialize(key));
* @return return bytes == null ? null : SerializeUtils.unSerialize(bytes);
*/ } catch (Exception e) {
public static boolean del(String... keys) { LOGGER.warn("jedis获取缓存失败:" + e.getMessage(), e);
try { }
jedisCluster.del(keys); return null;
} catch (Exception e) { }
LOGGER.warn("jedis批量删除缓存失败:" + e.getMessage(), e);
return false; /**
} * 根据缓存键清除Redis缓存中的对象.
return true; *
} * @param key
* @return
/** */
* 保存一个Map对象到redis中,长期有效 public static boolean delObject(Object key) {
* try {
* @param key jedisCluster.del(SerializeUtils.serialize(key));
* 键 } catch (Exception e) {
* @param hash LOGGER.warn("jedis删除缓存失败:" + e.getMessage(), e);
* Map组合的字符串 return false;
* @return }
*/ return true;
public static boolean hmset(String key, Map<String, String> hash) { }
try {
jedisCluster.hmset(key, hash); /**
} catch (Exception e) { * 根据缓存键批量清除Redis缓存中的对象.
LOGGER.warn("jedis缓存保存失败:" + e.getMessage(), e); *
return false; * @param keys
} * @return
return true; */
} public static boolean delObject(Object... keys) {
try {
/** jedisCluster.del(SerializeUtils.serialize(keys));
* 保存一个Map对象到redis中并指定过期时间 } catch (Exception e) {
* LOGGER.warn("jedis批量删除缓存失败:" + e.getMessage(), e);
* @param key return false;
* 键 }
* @param hash return true;
* Map组合的字符串 }
* @param seconds
* 时间 /**
* @return * 根据缓存键删除Redis缓存中的值.
*/ *
public static boolean hmset(String key, Map<String, String> hash, Integer seconds) { * @param key
try { * @return
jedisCluster.hmset(key, hash); */
expire(key, seconds); public static boolean del(String key) {
} catch (Exception e) { try {
LOGGER.warn("jedis缓存保存失败:" + e.getMessage(), e); jedisCluster.del(key);
return false; } catch (Exception e) {
} LOGGER.warn("jedis删除缓存失败:" + e.getMessage(), e);
return true; return false;
} }
return true;
/** }
* 添加一个内容到指定key的hash中
* /**
* @param key * 根据缓存键批量清除Redis缓存中的值.
* @param field *
* @param value * @param keys
* @return * @return
*/ */
public static Boolean hset(String key, String field, String value) { public static boolean del(String... keys) {
try { try {
jedisCluster.hset(key, field, value); jedisCluster.del(keys);
} catch (Exception e) { } catch (Exception e) {
LOGGER.warn("jedis添加内容到指定key的hash失败:" + e.getMessage(), e); LOGGER.warn("jedis批量删除缓存失败:" + e.getMessage(), e);
return false; return false;
} }
return true; return true;
} }
/** /**
* 添加一个内容到指定key的hash中,并转换成json格式 * 保存一个Map对象到redis中,长期有效
* *
* @param key * @param key 键
* @param field * @param hash Map组合的字符串
* @param value * @return
* @return */
*/ public static boolean hmset(String key, Map<String, String> hash) {
public static Boolean hset2Json(String key, String field, Object value) { try {
try { jedisCluster.hmset(key, hash);
jedisCluster.hset(key, field, JSONObject.toJSONString(value)); } catch (Exception e) {
} catch (Exception e) { LOGGER.warn("jedis缓存保存失败:" + e.getMessage(), e);
LOGGER.warn("jedis添加内容到指定key的hash失败:" + e.getMessage(), e); return false;
return false; }
} return true;
return true; }
}
/**
/** * 保存一个Map对象到redis中并指定过期时间
* 添加一个Fieid内容到指定key的hash中,如果Fieid存在就不添加,反之添加 *
* * @param key 键
* @param key * @param hash Map组合的字符串
* @param field * @param seconds 时间
* @param value * @return
* @return */
*/ public static boolean hmset(String key, Map<String, String> hash, Integer seconds) {
public static boolean hsetnx(String key, String field, String value) { try {
try { jedisCluster.hmset(key, hash);
jedisCluster.hsetnx(key, field, value); expire(key, seconds);
} catch (Exception e) { } catch (Exception e) {
LOGGER.warn("jedis缓存保存失败:" + e.getMessage(), e); LOGGER.warn("jedis缓存保存失败:" + e.getMessage(), e);
return false; return false;
} }
return true; return true;
} }
/** /**
* 添加一个Fieid内容到指定key的hash中,如果Fieid存在就不添加,反之添加 * 添加一个内容到指定key的hash中
* *
* @param key * @param key
* @param field * @param field
* @param value * @param value
* @return * @return
*/ */
public static boolean hsetnx2Json(String key, String field, Object value) { public static Boolean hset(String key, String field, String value) {
try { try {
jedisCluster.hsetnx(key, field, JSONObject.toJSONString(value)); jedisCluster.hset(key, field, value);
} catch (Exception e) { } catch (Exception e) {
LOGGER.warn("jedis缓存保存失败:" + e.getMessage(), e); LOGGER.warn("jedis添加内容到指定key的hash失败:" + e.getMessage(), e);
return false; return false;
} }
return true; return true;
} }
/** /**
* 指定Map中file的值自增 * 添加一个内容到指定key的hash中,并转换成json格式
* *
* @param key * @param key
* @param field * @param field
* @param value * @param value
* @return * @return
*/ */
public static Long hincrBy(String key, String field, Long value) { public static Boolean hset2Json(String key, String field, Object value) {
try { try {
return jedisCluster.hincrBy(key, field, value); jedisCluster.hset(key, field, JSONObject.toJSONString(value));
} catch (Exception e) { } catch (Exception e) {
LOGGER.warn("jedis缓存保存失败:" + e.getMessage(), e); LOGGER.warn("jedis添加内容到指定key的hash失败:" + e.getMessage(), e);
return null; return false;
} }
} return true;
}
/**
* 添加一个内容到指定key的hash中 /**
* * 添加一个Fieid内容到指定key的hash中,如果Fieid存在就不添加,反之添加
* @param key *
* @param field * @param key
* @param value * @param field
* @return * @param value
*/ * @return
@Deprecated */
public static Boolean hsetObject(Object key, Object field, Object value) { public static boolean hsetnx(String key, String field, String value) {
try { try {
jedisCluster.hset(SerializeUtils.serialize(key), SerializeUtils.serialize(field), jedisCluster.hsetnx(key, field, value);
SerializeUtils.serialize(value)); } catch (Exception e) {
} catch (Exception e) { LOGGER.warn("jedis缓存保存失败:" + e.getMessage(), e);
LOGGER.warn("jedis添加内容到指定key的hash失败:" + e.getMessage(), e); return false;
return false; }
} return true;
return true; }
}
/**
/** * 添加一个Fieid内容到指定key的hash中,如果Fieid存在就不添加,反之添加
* 根据缓存键获取Redis缓存中的Map.<br/> *
* * @param key
* @param key * @param field
* @param fields * @param value
* 具体的map键 * @return
* @return */
*/ public static boolean hsetnx2Json(String key, String field, Object value) {
public static Map<String, String> hgetAll(String key) { try {
try { jedisCluster.hsetnx(key, field, JSONObject.toJSONString(value));
return jedisCluster.hgetAll(key); } catch (Exception e) {
} catch (Exception e) { LOGGER.warn("jedis缓存保存失败:" + e.getMessage(), e);
LOGGER.warn("jedis获取缓存失败:" + e.getMessage(), e); return false;
return null; }
} return true;
} }
/** /**
* 根据缓存键获取Redis缓存中的Map.<br/> * 指定Map中file的值自增
* 可以指定Map具体的键值获取精确数据 *
* * @param key
* @param key * @param field
* @param fields * @param value
* 具体的map键 * @return
* @return */
*/ public static Long hincrBy(String key, String field, Long value) {
public static Map<String, String> hmget(String key, String... fields) { try {
Map<String, String> resultMap = Maps.newHashMap(); return jedisCluster.hincrBy(key, field, value);
try { } catch (Exception e) {
// 获取完整的map集合 LOGGER.warn("jedis缓存保存失败:" + e.getMessage(), e);
if (fields == null || fields.length == 0) { return null;
return jedisCluster.hgetAll(key); }
} else { }
List<String> resultList = jedisCluster.hmget(key, fields);
if (!ListUtils.isEmpty(resultList)) { /**
for (int i = 0; i < resultList.size(); i++) { * 添加一个内容到指定key的hash中
resultMap.put(fields[i], resultList.get(i)); *
} * @param key
} * @param field
} * @param value
} catch (Exception e) { * @return
LOGGER.warn("jedis获取缓存失败:" + e.getMessage(), e); */
return null; @Deprecated
} public static Boolean hsetObject(Object key, Object field, Object value) {
return resultMap; try {
} jedisCluster.hset(SerializeUtils.serialize(key), SerializeUtils.serialize(field),
SerializeUtils.serialize(value));
/** } catch (Exception e) {
* 从指定hash中取值 LOGGER.warn("jedis添加内容到指定key的hash失败:" + e.getMessage(), e);
* return false;
* @param key }
* @param field return true;
* @return }
*/
public static String hget(String key, String field) { /**
try { * 根据缓存键获取Redis缓存中的Map.<br/>
return jedisCluster.hget(key, field); *
} catch (Exception e) { * @param key
LOGGER.warn("jedis从指定hash中取值失败:" + e.getMessage(), e); * @param fields 具体的map键
return null; * @return
} */
} public static Map<String, String> hgetAll(String key) {
try {
/** return jedisCluster.hgetAll(key);
* 从指定hash中取值,并将取到的json字符串转换成指定的对象 } catch (Exception e) {
* LOGGER.warn("jedis获取缓存失败:" + e.getMessage(), e);
* @param key return null;
* @param field }
* @param clazz }
* @return
*/ /**
public static <T> T hgetJson2Class(String key, String field, Class<T> clazz) { * 根据缓存键获取Redis缓存中的Map.<br/>
try { * 可以指定Map具体的键值获取精确数据
return JSONObject.parseObject(jedisCluster.hget(key, field), clazz); *
} catch (Exception e) { * @param key
LOGGER.warn("jedis从指定hash中取值失败:" + e.getMessage(), e); * @param fields 具体的map键
return null; * @return
} */
} public static Map<String, String> hmget(String key, String... fields) {
Map<String, String> resultMap = Maps.newHashMap();
/** try {
* 从指定hash中取值,并将取到的json字符串转换成指定的对象集合 // 获取完整的map集合
* if (fields == null || fields.length == 0) {
* @param key return jedisCluster.hgetAll(key);
* @param field } else {
* @param clazz List<String> resultList = jedisCluster.hmget(key, fields);
* @return if (!ListUtils.isEmpty(resultList)) {
*/ for (int i = 0; i < resultList.size(); i++) {
public static <T> List<T> hgetJson2List(String key, String field, Class<T> clazz) { resultMap.put(fields[i], resultList.get(i));
try { }
return JSONArray.parseArray(jedisCluster.hget(key, field), clazz); }
} catch (Exception e) { }
LOGGER.warn("jedis从指定hash中取值失败:" + e.getMessage(), e); } catch (Exception e) {
return null; LOGGER.warn("jedis获取缓存失败:" + e.getMessage(), e);
} return null;
} }
return resultMap;
/** }
* 从指定hash中取值
* /**
* @param key * 从指定hash中取值
* @param field *
* @return * @param key
*/ * @param field
@Deprecated * @return
public static Object hgetObject(Object key, Object field) { */
try { public static String hget(String key, String field) {
byte[] bytes = jedisCluster.hget(SerializeUtils.serialize(key), SerializeUtils.serialize(field)); try {
return bytes == null ? null : SerializeUtils.unSerialize(bytes); return jedisCluster.hget(key, field);
} catch (Exception e) { } catch (Exception e) {
LOGGER.warn("jedis从指定hash中取对象失败:" + e.getMessage(), e); LOGGER.warn("jedis从指定hash中取值失败:" + e.getMessage(), e);
} return null;
return null; }
} }
/** /**
* 根据缓存键删除map中的指定键值 * 从指定hash中取值,并将取到的json字符串转换成指定的对象
* *
* @param key * @param key
* 缓存键 * @param field
* @param field * @param clazz
* map键值 * @return
* @return 删除成功返回1,失败返回0 */
*/ public static <T> T hgetJson2Class(String key, String field, Class<T> clazz) {
public static Boolean hdel(String key, String... fields) { try {
long result = 0L; return JSONObject.parseObject(jedisCluster.hget(key, field), clazz);
try { } catch (Exception e) {
result = jedisCluster.hdel(key, fields); LOGGER.warn("jedis从指定hash中取值失败:" + e.getMessage(), e);
} catch (Exception e) { return null;
LOGGER.warn("jedis删除map中的指定键值失败:" + e.getMessage(), e); }
} }
return result > 0 ? true : false;
} /**
* 从指定hash中取值,并将取到的json字符串转换成指定的对象集合
/** *
* 从hash中删除指定filed的对象 * @param key
* * @param field
* @param key * @param clazz
* @param field * @return
* @return */
*/ public static <T> List<T> hgetJson2List(String key, String field, Class<T> clazz) {
@Deprecated try {
public static Boolean hdelObject(Object key, Object... field) { return JSONArray.parseArray(jedisCluster.hget(key, field), clazz);
long result = 0L; } catch (Exception e) {
try { LOGGER.warn("jedis从指定hash中取值失败:" + e.getMessage(), e);
result = jedisCluster.hdel(SerializeUtils.serialize(key), SerializeUtils.serialize(field)); return null;
} catch (Exception e) { }
LOGGER.warn("jedis从hash中删除指定filed的对象失败:" + e.getMessage(), e); }
}
return result > 0 ? true : false; /**
} * 从指定hash中取值
*
/** * @param key
* 获取指定key中存放的hash值个数 * @param field
* * @return
* @param key */
* @return @Deprecated
*/ public static Object hgetObject(Object key, Object field) {
public static Long hlen(String key) { try {
try { byte[] bytes = jedisCluster.hget(SerializeUtils.serialize(key), SerializeUtils.serialize(field));
return jedisCluster.hlen(key); return bytes == null ? null : SerializeUtils.unSerialize(bytes);
} catch (Exception e) { } catch (Exception e) {
LOGGER.warn("jedis获取指定key中存放的hash值个数失败:" + e.getMessage(), e); LOGGER.warn("jedis从指定hash中取对象失败:" + e.getMessage(), e);
} }
return null; return null;
} }
/** /**
* 判断指定key中是否存在fileId键 * 根据缓存键删除map中的指定键值
* *
* @param key * @param key 缓存键
* @return * @param field map键值
*/ * @return 删除成功返回1,失败返回0
public static Boolean hexists(String key, String fileId) { */
try { public static Boolean hdel(String key, String... fields) {
return jedisCluster.hexists(key, fileId); long result = 0L;
} catch (Exception e) { try {
LOGGER.warn("jedis判断指定key中是否存在fileId键失败:" + e.getMessage(), e); result = jedisCluster.hdel(key, fields);
} } catch (Exception e) {
return null; LOGGER.warn("jedis删除map中的指定键值失败:" + e.getMessage(), e);
} }
return result > 0 ? true : false;
/** }
* 获取指定key中存放的hash值个数
* /**
* @param key * 从hash中删除指定filed的对象
* @return *
*/ * @param key
public static Long hlenObject(Object key) { * @param field
try { * @return
return jedisCluster.hlen(SerializeUtils.serialize(key)); */
} catch (Exception e) { @Deprecated
LOGGER.warn("jedis获取指定key中存放的hash值个数失败:" + e.getMessage(), e); public static Boolean hdelObject(Object key, Object... field) {
} long result = 0L;
return null; try {
} result = jedisCluster.hdel(SerializeUtils.serialize(key), SerializeUtils.serialize(field));
} catch (Exception e) {
/** LOGGER.warn("jedis从hash中删除指定filed的对象失败:" + e.getMessage(), e);
* 获取指定key中map对象中的所有key }
* return result > 0 ? true : false;
* @param key }
* @return
*/ /**
public static Set<String> hkeys(String key) { * 获取指定key中存放的hash值个数
try { *
return jedisCluster.hkeys(key); * @param key
} catch (Exception e) { * @return
LOGGER.warn("jedis获取指定key中map对象中的所有key失败:" + e.getMessage(), e); */
} public static Long hlen(String key) {
return null; try {
} return jedisCluster.hlen(key);
} catch (Exception e) {
/** LOGGER.warn("jedis获取指定key中存放的hash值个数失败:" + e.getMessage(), e);
* 添加内容到指定key的list中,先进后出 }
* return null;
* @param key }
* @param field
* @param value /**
* @return * 判断指定key中是否存在fileId键
*/ *
public static Boolean lpush(String key, String value) { * @param key
Long result = 0L; * @return
try { */
result = jedisCluster.lpush(key, value); public static Boolean hexists(String key, String fileId) {
} catch (Exception e) { try {
LOGGER.warn("jedis添加内容到指定key的list中失败:" + e.getMessage(), e); return jedisCluster.hexists(key, fileId);
} } catch (Exception e) {
return result == 0 ? false : true; LOGGER.warn("jedis判断指定key中是否存在fileId键失败:" + e.getMessage(), e);
} }
return null;
/** }
* 添加内容到指定key的list中,先进后出
* /**
* @param key * 获取指定key中存放的hash值个数
* @param obj *
* @return * @param key
*/ * @return
public static Boolean lpushJson(String key, Object obj) { */
Long result = 0L; public static Long hlenObject(Object key) {
try { try {
result = jedisCluster.lpush(key, JSONObject.toJSONString(obj)); return jedisCluster.hlen(SerializeUtils.serialize(key));
} catch (Exception e) { } catch (Exception e) {
LOGGER.warn("jedis添加内容到指定key的list中失败:" + e.getMessage(), e); LOGGER.warn("jedis获取指定key中存放的hash值个数失败:" + e.getMessage(), e);
} }
return result == 0 ? false : true; return null;
} }
/** /**
* 添加内容到指定key的list中,先进后出 * 获取指定key中map对象中的所有key
* *
* @param key * @param key
* @param value * @return
* @return */
*/ public static Set<String> hkeys(String key) {
public static Boolean lpushObject(Object key, Object value) { try {
Long result = 0L; return jedisCluster.hkeys(key);
try { } catch (Exception e) {
result = jedisCluster.lpush(SerializeUtils.serialize(key), SerializeUtils.serialize(value)); LOGGER.warn("jedis获取指定key中map对象中的所有key失败:" + e.getMessage(), e);
} catch (Exception e) { }
LOGGER.warn("jedis添加内容到指定key的list中失败:" + e.getMessage(), e); return null;
} }
return result == 0 ? false : true;
} /**
* 添加内容到指定key的list中,先进后出
/** *
* 添加内容到指定key的list中,先进先出 * @param key
* * @param field
* @param key * @param value
* @param field * @return
* @param value */
* @return public static Boolean lpush(String key, String value) {
*/ Long result = 0L;
public static Boolean rpush(String key, String value) { try {
Long result = 0L; result = jedisCluster.lpush(key, value);
try { } catch (Exception e) {
result = jedisCluster.rpush(key, value); LOGGER.warn("jedis添加内容到指定key的list中失败:" + e.getMessage(), e);
} catch (Exception e) { }
LOGGER.warn("jedis添加内容到指定key的list中失败:" + e.getMessage(), e); return result == 0 ? false : true;
} }
return result == 0 ? false : true;
} /**
* 添加内容到指定key的list中,先进后出
/** *
* 添加内容到指定key的list中,先进先出 * @param key
* * @param obj
* @param key * @return
* @param obj */
* @return public static Boolean lpushJson(String key, Object obj) {
*/ Long result = 0L;
public static Boolean rpushJson(String key, Object obj) { try {
Long result = 0L; result = jedisCluster.lpush(key, JSONObject.toJSONString(obj));
try { } catch (Exception e) {
result = jedisCluster.rpush(key, JSONObject.toJSONString(obj)); LOGGER.warn("jedis添加内容到指定key的list中失败:" + e.getMessage(), e);
} catch (Exception e) { }
LOGGER.warn("jedis添加内容到指定key的list中失败:" + e.getMessage(), e); return result == 0 ? false : true;
} }
return result == 0 ? false : true;
} /**
* 添加内容到指定key的list中,先进后出
/** *
* 添加内容到指定key的list中,先进先出 * @param key
* * @param value
* @param key * @return
* @param field */
* @param value public static Boolean lpushObject(Object key, Object value) {
* @return Long result = 0L;
*/ try {
public static Boolean rpushObject(Object key, Object value) { result = jedisCluster.lpush(SerializeUtils.serialize(key), SerializeUtils.serialize(value));
Long result = 0L; } catch (Exception e) {
try { LOGGER.warn("jedis添加内容到指定key的list中失败:" + e.getMessage(), e);
result = jedisCluster.rpush(SerializeUtils.serialize(key), SerializeUtils.serialize(value)); }
} catch (Exception e) { return result == 0 ? false : true;
LOGGER.warn("jedis添加内容到指定key的list中失败:" + e.getMessage(), e); }
}
return result == 0 ? false : true; /**
} * 添加内容到指定key的list中,先进先出
*
/** * @param key
* 获取指定key的list集合 * @param field
* * @param value
* @param key * @return
* @param start */
* list中的起始位置,从0开始 public static Boolean rpush(String key, String value) {
* @param len Long result = 0L;
* 长度,-1获取所有 try {
* @return result = jedisCluster.rpush(key, value);
*/ } catch (Exception e) {
public static List<String> lrange(String key, long start, long len) { LOGGER.warn("jedis添加内容到指定key的list中失败:" + e.getMessage(), e);
try { }
return jedisCluster.lrange(key, start, len); return result == 0 ? false : true;
} catch (Exception e) { }
LOGGER.warn("jedis获取指定key的list集合失败:" + e.getMessage(), e);
} /**
return null; * 添加内容到指定key的list中,先进先出
} *
* @param key
/** * @param obj
* 获取指定key的list长度 * @return
* */
* @param key public static Boolean rpushJson(String key, Object obj) {
* @return Long result = 0L;
*/ try {
public static Long llen(String key) { result = jedisCluster.rpush(key, JSONObject.toJSONString(obj));
try { } catch (Exception e) {
return jedisCluster.llen(key); LOGGER.warn("jedis添加内容到指定key的list中失败:" + e.getMessage(), e);
} catch (Exception e) { }
LOGGER.warn("jedis获取指定key的list长度失败:" + e.getMessage(), e); return result == 0 ? false : true;
} }
return null;
} /**
* 添加内容到指定key的list中,先进先出
/** *
* 获取指定key的list长度 * @param key
* * @param field
* @param key * @param value
* @return * @return
*/ */
public static Long llenObject(Object key) { public static Boolean rpushObject(Object key, Object value) {
try { Long result = 0L;
return jedisCluster.llen(SerializeUtils.serialize(key)); try {
} catch (Exception e) { result = jedisCluster.rpush(SerializeUtils.serialize(key), SerializeUtils.serialize(value));
LOGGER.warn("jedis获取指定key的list长度失败:" + e.getMessage(), e); } catch (Exception e) {
} LOGGER.warn("jedis添加内容到指定key的list中失败:" + e.getMessage(), e);
return null; }
} return result == 0 ? false : true;
}
/**
* 列表出栈(左端) /**
* * 获取指定key的list集合
* @param key *
* @return * @param key
*/ * @param start list中的起始位置,从0开始
public static String lpop(String key) { * @param len 长度,-1获取所有
try { * @return
return jedisCluster.lpop(key); */
} catch (Exception e) { public static List<String> lrange(String key, long start, long len) {
LOGGER.warn("jedis列表出栈(左端)失败:" + e.getMessage(), e); try {
} return jedisCluster.lrange(key, start, len);
return null; } catch (Exception e) {
} LOGGER.warn("jedis获取指定key的list集合失败:" + e.getMessage(), e);
}
/** return null;
* 列表出栈(左端) }
*
* @param key /**
* @return * 获取指定key的list长度
*/ *
public static List<String> lpop(String key, long count) { * @param key
try { * @return
List<String> list = new ArrayList<String>(); */
for (int i = 0; i < count; i++) { public static Long llen(String key) {
String vel = jedisCluster.lpop(key); try {
if (vel != null) { return jedisCluster.llen(key);
list.add(vel); } catch (Exception e) {
} LOGGER.warn("jedis获取指定key的list长度失败:" + e.getMessage(), e);
} }
return list; return null;
} catch (Exception e) { }
LOGGER.warn("jedis列表出栈(左端)失败:" + e.getMessage(), e);
} /**
return null; * 获取指定key的list长度
} *
* @param key
/** * @return
* 列表出栈(左端) */
* public static Long llenObject(Object key) {
* @param key try {
* @return return jedisCluster.llen(SerializeUtils.serialize(key));
*/ } catch (Exception e) {
public static <T> T lpopJson(String key, Class<T> clazz) { LOGGER.warn("jedis获取指定key的list长度失败:" + e.getMessage(), e);
try { }
String vel = jedisCluster.lpop(key); return null;
if (!StringUtil.isEmpty(vel)) { }
return JSONObject.parseObject(vel, clazz);
} /**
} catch (Exception e) { * 列表出栈(左端)
LOGGER.warn("jedis列表出栈(左端)失败:" + e.getMessage(), e); *
} * @param key
return null; * @return
} */
public static String lpop(String key) {
/** try {
* 列表出栈(左端) return jedisCluster.lpop(key);
* } catch (Exception e) {
* @param key LOGGER.warn("jedis列表出栈(左端)失败:" + e.getMessage(), e);
* @return }
*/ return null;
public static <T> List<T> lpopJson(String key, long count, Class<T> clazz) { }
try {
List<T> list = new ArrayList<T>(); /**
for (int i = 0; i < count; i++) { * 列表出栈(左端)
String vel = jedisCluster.lpop(key); *
if (!StringUtil.isEmpty(vel)) { * @param key
list.add(JSONObject.parseObject(vel, clazz)); * @return
} */
} public static List<String> lpop(String key, long count) {
return list; try {
} catch (Exception e) { List<String> list = new ArrayList<String>();
LOGGER.warn("jedis列表出栈(左端)失败:" + e.getMessage(), e); for (int i = 0; i < count; i++) {
} String vel = jedisCluster.lpop(key);
return null; if (vel != null) {
} list.add(vel);
}
/** }
* 列表出栈(右端) return list;
* } catch (Exception e) {
* @param key LOGGER.warn("jedis列表出栈(左端)失败:" + e.getMessage(), e);
* @return }
*/ return null;
public static String rpop(String key) { }
try {
return jedisCluster.rpop(key); /**
} catch (Exception e) { * 列表出栈(左端)
LOGGER.warn("jedis列表出栈(右端)失败:" + e.getMessage(), e); *
} * @param key
return null; * @return
} */
public static <T> T lpopJson(String key, Class<T> clazz) {
/** try {
* 列表出栈(右端) String vel = jedisCluster.lpop(key);
* if (!StringUtil.isEmpty(vel)) {
* @param key return JSONObject.parseObject(vel, clazz);
* @return }
*/ } catch (Exception e) {
public static List<String> rpop(String key, long count) { LOGGER.warn("jedis列表出栈(左端)失败:" + e.getMessage(), e);
try { }
List<String> list = new ArrayList<String>(); return null;
for (int i = 0; i < count; i++) { }
String vel = jedisCluster.rpop(key);
if (vel != null) { /**
list.add(vel); * 列表出栈(左端)
} *
} * @param key
return list; * @return
} catch (Exception e) { */
LOGGER.warn("jedis列表出栈(右端)失败:" + e.getMessage(), e); public static <T> List<T> lpopJson(String key, long count, Class<T> clazz) {
} try {
return null; List<T> list = new ArrayList<T>();
} for (int i = 0; i < count; i++) {
String vel = jedisCluster.lpop(key);
/** if (!StringUtil.isEmpty(vel)) {
* 列表出栈(右端) list.add(JSONObject.parseObject(vel, clazz));
* }
* @param key }
* @return return list;
*/ } catch (Exception e) {
public static <T> T rpopJson(String key, Class<T> clazz) { LOGGER.warn("jedis列表出栈(左端)失败:" + e.getMessage(), e);
try { }
String vel = jedisCluster.rpop(key); return null;
if (!StringUtil.isEmpty(vel)) { }
return JSONObject.parseObject(vel, clazz);
} /**
} catch (Exception e) { * 列表出栈(右端)
LOGGER.warn("jedis列表出栈(右端)失败:" + e.getMessage(), e); *
} * @param key
return null; * @return
} */
public static String rpop(String key) {
/** try {
* 列表出栈(右端) return jedisCluster.rpop(key);
* } catch (Exception e) {
* @param key LOGGER.warn("jedis列表出栈(右端)失败:" + e.getMessage(), e);
* @return }
*/ return null;
public static <T> List<T> rpopJson(String key, long count, Class<T> clazz) { }
try {
List<T> list = new ArrayList<T>(); /**
for (int i = 0; i < count; i++) { * 列表出栈(右端)
String vel = jedisCluster.rpop(key); *
if (!StringUtil.isEmpty(vel)) { * @param key
list.add(JSONObject.parseObject(vel, clazz)); * @return
} */
} public static List<String> rpop(String key, long count) {
return list; try {
} catch (Exception e) { List<String> list = new ArrayList<String>();
LOGGER.warn("jedis列表出栈(右端)失败:" + e.getMessage(), e); for (int i = 0; i < count; i++) {
} String vel = jedisCluster.rpop(key);
return null; if (vel != null) {
} list.add(vel);
}
/** }
* 删除指定区间之外的元素 return list;
* } catch (Exception e) {
* @param key LOGGER.warn("jedis列表出栈(右端)失败:" + e.getMessage(), e);
* @return }
*/ return null;
public static String ltrim(String key, long start, long len) { }
try {
return jedisCluster.ltrim(key, start, len); /**
} catch (Exception e) { * 列表出栈(右端)
LOGGER.warn("jedis删除指定区间之外的元素失败:" + e.getMessage(), e); *
} * @param key
return null; * @return
} */
public static <T> T rpopJson(String key, Class<T> clazz) {
/** try {
* 有序序列(Sort-Set)集合:添加数据 String vel = jedisCluster.rpop(key);
* @param key if (!StringUtil.isEmpty(vel)) {
* @return return JSONObject.parseObject(vel, clazz);
*/ }
public static boolean zset(String key, double score, String member) { } catch (Exception e) {
try { LOGGER.warn("jedis列表出栈(右端)失败:" + e.getMessage(), e);
jedisCluster.zadd(key, score, member); }
} catch (Exception e) { return null;
LOGGER.error("jedis有序序列集合:添加数据失败:" + e.getMessage(), e); }
return false;
} /**
return true; * 列表出栈(右端)
} *
* @param key
/** * @return
* 获取指定key的Sort-Set集合长度 */
* @return public static <T> List<T> rpopJson(String key, long count, Class<T> clazz) {
*/ try {
public static Long zcard(String key) { List<T> list = new ArrayList<T>();
try { for (int i = 0; i < count; i++) {
return jedisCluster.zcard(key); String vel = jedisCluster.rpop(key);
} catch (Exception e) { if (!StringUtil.isEmpty(vel)) {
LOGGER.error("jedis有序序列集合长度失败:" + e.getMessage(), e); list.add(JSONObject.parseObject(vel, clazz));
} }
return null; }
} return list;
} catch (Exception e) {
/** LOGGER.warn("jedis列表出栈(右端)失败:" + e.getMessage(), e);
* 获取指定key的Sort-Set集合中member元素所在的位置排行(从 0 开始) }
* @return return null;
*/ }
public static Long zrank(String key, String member) {
try { /**
return jedisCluster.zrank(key, member); * 删除指定区间之外的元素
} catch (Exception e) { *
LOGGER.error("jedis获取有序序列集合中MEMBER位置失败:" + e.getMessage(), e); * @param key
} * @return
return null; */
} public static String ltrim(String key, long start, long len) {
try {
/** return jedisCluster.ltrim(key, start, len);
* 获取指定key的Sort-Set集合的元素(按照score从小到大排序) } catch (Exception e) {
* @return LOGGER.warn("jedis删除指定区间之外的元素失败:" + e.getMessage(), e);
*/ }
public static Set<String> zrange(String key, long start, long end) { return null;
try { }
return jedisCluster.zrange(key, start, end);
} catch (Exception e) { /**
LOGGER.error("jedis有序序列集合的元素失败:" + e.getMessage(), e); * 有序序列(Sort-Set)集合:添加数据
} *
return null; * @param key
} * @return
*/
/** public static boolean zset(String key, double score, String member) {
* 获取指定key的Sort-Set集合的元素(按照score从大到小排序) try {
* @return jedisCluster.zadd(key, score, member);
*/ } catch (Exception e) {
public static Set<String> zrevrange(String key, long start, long end) { LOGGER.error("jedis有序序列集合:添加数据失败:" + e.getMessage(), e);
try { return false;
return jedisCluster.zrevrange(key, start, end); }
} catch (Exception e) { return true;
LOGGER.error("jedis有序序列集合的元素失败:" + e.getMessage(), e); }
}
return null; /**
} * 获取指定key的Sort-Set集合长度
*
/** * @return
* 删除指定key的Sort-Set集合的元素 */
* @return public static Long zcard(String key) {
*/ try {
public static boolean zrem(String key, long start, long end) { return jedisCluster.zcard(key);
try { } catch (Exception e) {
jedisCluster.zremrangeByRank(key, start, end); LOGGER.error("jedis有序序列集合长度失败:" + e.getMessage(), e);
} catch (Exception e) { }
LOGGER.error("jedis删除有序序列集合的元素失败:" + e.getMessage(), e); return null;
return false; }
}
return true; /**
} * 获取指定key的Sort-Set集合中member元素所在的位置排行(从 0 开始)
*
/** * @return
* 根据clazz和key获取对应 的类型 */
* public static Long zrank(String key, String member) {
* @param key try {
* @param clazz return jedisCluster.zrank(key, member);
* @return } catch (Exception e) {
*/ LOGGER.error("jedis获取有序序列集合中MEMBER位置失败:" + e.getMessage(), e);
public static <T> T getClass(Object key, Class<T> clazz) { }
try { return null;
Object object = getObject(key); }
return object == null ? null : clazz.cast(object);
} catch (Exception e) { /**
LOGGER.warn("jedis根据clazz和key获取对应 的类型:" + e.getMessage(), e); * 获取指定key的Sort-Set集合的元素(按照score从小到大排序)
} *
return null; * @return
} */
public static Set<String> zrange(String key, long start, long end) {
/** try {
* 根据clazz和key获取对应的list return jedisCluster.zrange(key, start, end);
* } catch (Exception e) {
* @param key LOGGER.error("jedis有序序列集合的元素失败:" + e.getMessage(), e);
* @param clazz }
* @return return null;
*/ }
@SuppressWarnings("unchecked")
public static <T> List<T> getList(Object key, Class<T> clazz) { /**
try { * 获取指定key的Sort-Set集合的元素(按照score从大到小排序)
Object object = getObject(key); *
return object == null ? null : (List<T>) object; * @return
} catch (Exception e) { */
LOGGER.warn("jedis根据clazz和key获取对应的list:" + e.getMessage(), e); public static Set<String> zrevrange(String key, long start, long end) {
} try {
return null; return jedisCluster.zrevrange(key, start, end);
} } catch (Exception e) {
LOGGER.error("jedis有序序列集合的元素失败:" + e.getMessage(), e);
/** }
* 根据clazz和key获取对应的map return null;
* }
* @param key
* @param clazz /**
* @return * 删除指定key的Sort-Set集合的元素
*/ *
@SuppressWarnings("unchecked") * @return
public static <K, V> Map<K, V> getMap(Object key, Class<K> kClazz, Class<V> vClazz) { */
try { public static boolean zrem(String key, long start, long end) {
Object object = getObject(key); try {
return object == null ? null : (Map<K, V>) object; jedisCluster.zremrangeByRank(key, start, end);
} catch (Exception e) { } catch (Exception e) {
LOGGER.warn("jedis根据clazz和key获取对应的map:" + e.getMessage(), e); LOGGER.error("jedis删除有序序列集合的元素失败:" + e.getMessage(), e);
} return false;
return null; }
} return true;
}
/**
* 根据key,及clazz获取对象.使用json进行转换 /**
* * 根据clazz和key获取对应 的类型
* @param key *
* @param clazz * @param key
* @return * @param clazz
*/ * @return
public static <T> T getJson(String key, Class<T> clazz) { */
String jsonValue = get(key); public static <T> T getClass(Object key, Class<T> clazz) {
if (StringUtil.isEmpty(jsonValue)) { try {
return null; Object object = getObject(key);
} return object == null ? null : clazz.cast(object);
try { } catch (Exception e) {
return JSONObject.parseObject(jsonValue, clazz); LOGGER.warn("jedis根据clazz和key获取对应 的类型:" + e.getMessage(), e);
} catch (Exception e) { }
LOGGER.warn("jedis根据key获取clazz对象,JSON转换异常:" + e.getMessage(), e); return null;
} }
return null;
} /**
* 根据clazz和key获取对应的list
/** *
* 根据key,及clazz获取对象集合.使用json进行转换 * @param key
* * @param clazz
* @param key * @return
* @param clazz */
* @return @SuppressWarnings("unchecked")
*/ public static <T> List<T> getList(Object key, Class<T> clazz) {
public static <T> List<T> getJsonList(String key, Class<T> clazz) { try {
String jsonValue = get(key); Object object = getObject(key);
if (StringUtil.isEmpty(jsonValue)) { return object == null ? null : (List<T>) object;
return null; } catch (Exception e) {
} LOGGER.warn("jedis根据clazz和key获取对应的list:" + e.getMessage(), e);
try { }
return JSONArray.parseArray(jsonValue, clazz); return null;
} catch (Exception e) { }
LOGGER.warn("jedis根据key获取clazz对象,JSON转换异常:" + e.getMessage(), e);
} /**
return null; * 根据clazz和key获取对应的map
} *
* @param key
/** * @param clazz
* 缓存对象.使用json进行转换 * @return
* */
* @param key @SuppressWarnings("unchecked")
* @param obj public static <K, V> Map<K, V> getMap(Object key, Class<K> kClazz, Class<V> vClazz) {
*/ try {
public static Boolean setJson(String key, Object obj) { Object object = getObject(key);
try { return object == null ? null : (Map<K, V>) object;
return set(key, JSONObject.toJSONString(obj)); } catch (Exception e) {
} catch (Exception e) { LOGGER.warn("jedis根据clazz和key获取对应的map:" + e.getMessage(), e);
LOGGER.warn("jedis根据key缓存对象,JSON转换异常:" + e.getMessage(), e); }
} return null;
return false; }
}
/**
/** * 根据key,及clazz获取对象.使用json进行转换
* 缓存对象.使用json进行转换,带有效期 *
* * @param key
* @param key * @param clazz
* @param obj * @return
* @param seconds */
* 有效期(秒) public static <T> T getJson(String key, Class<T> clazz) {
* @return String jsonValue = get(key);
*/ if (StringUtil.isEmpty(jsonValue)) {
public static Boolean setJson(String key, Object obj, Integer seconds) { return null;
try { }
return set(key, JSONObject.toJSONString(obj), seconds); try {
} catch (Exception e) { return JSONObject.parseObject(jsonValue, clazz);
LOGGER.warn("jedis根据key缓存对象,JSON转换异常:" + e.getMessage(), e); } catch (Exception e) {
} LOGGER.warn("jedis根据key获取clazz对象,JSON转换异常:" + e.getMessage(), e);
return false; }
} return null;
}
/**
* 缓存对象集合.使用json进行转换 /**
* * 根据key,及clazz获取对象集合.使用json进行转换
* @param key *
* @param obj * @param key
* @return * @param clazz
*/ * @return
public static Boolean setJsonList(String key, Object obj) { */
try { public static <T> List<T> getJsonList(String key, Class<T> clazz) {
return set(key, JSONArray.toJSONString(obj)); String jsonValue = get(key);
} catch (Exception e) { if (StringUtil.isEmpty(jsonValue)) {
LOGGER.warn("jedis根据key缓存对象,JSON转换异常:" + e.getMessage(), e); return null;
} }
return false; try {
} return JSONArray.parseArray(jsonValue, clazz);
} catch (Exception e) {
/** LOGGER.warn("jedis根据key获取clazz对象,JSON转换异常:" + e.getMessage(), e);
* 缓存对象集合.使用json进行转换 }
* return null;
* @param key }
* @param obj
* @return /**
*/ * 缓存对象.使用json进行转换
public static Boolean setJsonList(String key, Object obj, Integer seconds) { *
try { * @param key
return set(key, JSONArray.toJSONString(obj), seconds); * @param obj
} catch (Exception e) { */
LOGGER.warn("jedis根据key缓存对象,JSON转换异常:" + e.getMessage(), e); public static Boolean setJson(String key, Object obj) {
} try {
return false; return set(key, JSONObject.toJSONString(obj));
} } catch (Exception e) {
LOGGER.warn("jedis根据key缓存对象,JSON转换异常:" + e.getMessage(), e);
/** }
* 设置超时时间 return false;
* }
* @param key
* @param seconds /**
* @return * 缓存对象.使用json进行转换,带有效期
*/ *
public static boolean expire(String key, Integer seconds) { * @param key
try { * @param obj
jedisCluster.expire(key, seconds == null || seconds < 1 ? REDIS_SESSION_TIMEOUT : seconds); * @param seconds 有效期(秒)
} catch (Exception e) { * @return
LOGGER.warn("jedis设置超时时间失败:" + e.getMessage(), e); */
return false; public static Boolean setJson(String key, Object obj, Integer seconds) {
} try {
return true; return set(key, JSONObject.toJSONString(obj), seconds);
} } catch (Exception e) {
LOGGER.warn("jedis根据key缓存对象,JSON转换异常:" + e.getMessage(), e);
/** }
* 设置超时时间 return false;
* }
* @param key
* @param seconds /**
* 超时时间(单位为秒) * 缓存对象集合.使用json进行转换
* @return *
*/ * @param key
public static boolean expireObject(Object key, Integer seconds) { * @param obj
try { * @return
jedisCluster.expire(SerializeUtils.serialize(key), */
seconds == null || seconds < 1 ? REDIS_SESSION_TIMEOUT : seconds); public static Boolean setJsonList(String key, Object obj) {
} catch (Exception e) { try {
LOGGER.warn("jedis设置超时时间失败:" + e.getMessage(), e); return set(key, JSONArray.toJSONString(obj));
return false; } catch (Exception e) {
} LOGGER.warn("jedis根据key缓存对象,JSON转换异常:" + e.getMessage(), e);
return true; }
} return false;
}
/**
* 查看键还有多长时间过期(秒) /**
* * 缓存对象集合.使用json进行转换
* @param key *
* @return * @param key
*/ * @param obj
public static Long ttl(String key) { * @return
try { */
return jedisCluster.ttl(key); public static Boolean setJsonList(String key, Object obj, Integer seconds) {
} catch (Exception e) { try {
LOGGER.warn("jedis查看过期时间失败:" + e.getMessage(), e); return set(key, JSONArray.toJSONString(obj), seconds);
} } catch (Exception e) {
return null; LOGGER.warn("jedis根据key缓存对象,JSON转换异常:" + e.getMessage(), e);
} }
return false;
/** }
* 查看键还有多长时间过期(秒)
* /**
* @param key * 设置超时时间
* @return *
*/ * @param key
public static Long ttlObject(Object key) { * @param seconds
try { * @return
return jedisCluster.ttl(SerializeUtils.serialize(key)); */
} catch (Exception e) { public static boolean expire(String key, Integer seconds) {
LOGGER.warn("jedis查看过期时间失败:" + e.getMessage(), e); try {
} jedisCluster.expire(key, seconds == null || seconds < 1 ? REDIS_SESSION_TIMEOUT : seconds);
return null; } catch (Exception e) {
} LOGGER.warn("jedis设置超时时间失败:" + e.getMessage(), e);
return false;
/** }
* 判断一个key是否存在 return true;
* }
* @param key
* @return /**
*/ * 设置超时时间
public static boolean exists(String key) { *
try { * @param key
return jedisCluster.exists(key); * @param seconds 超时时间(单位为秒)
} catch (Exception e) { * @return
LOGGER.warn("jedis判断key是否存在失败:" + e.getMessage(), e); */
} public static boolean expireObject(Object key, Integer seconds) {
return false; try {
} jedisCluster.expire(SerializeUtils.serialize(key),
seconds == null || seconds < 1 ? REDIS_SESSION_TIMEOUT : seconds);
/** } catch (Exception e) {
* 判断一个key是否存在 LOGGER.warn("jedis设置超时时间失败:" + e.getMessage(), e);
* return false;
* @param key }
* @return return true;
*/ }
public static boolean existsObject(Object key) {
try { /**
return jedisCluster.exists(SerializeUtils.serialize(key)); * 查看键还有多长时间过期(秒)
} catch (Exception e) { *
LOGGER.warn("jedis判断key是否存在失败:" + e.getMessage(), e); * @param key
} * @return
return false; */
} public static Long ttl(String key) {
try {
/** return jedisCluster.ttl(key);
* 缓存值自增1 } catch (Exception e) {
* LOGGER.warn("jedis查看过期时间失败:" + e.getMessage(), e);
* @param key }
* @return return null;
*/ }
public static Long incr(String key) {
Long result = null; /**
try { * 查看键还有多长时间过期(秒)
result = jedisCluster.incr(key); *
} catch (Exception e) { * @param key
LOGGER.warn("jedis缓存值自增1失败:" + e.getMessage(), e); * @return
} */
return result; public static Long ttlObject(Object key) {
} try {
return jedisCluster.ttl(SerializeUtils.serialize(key));
/** } catch (Exception e) {
* 缓存值自增1 LOGGER.warn("jedis查看过期时间失败:" + e.getMessage(), e);
* }
* @param key return null;
* @return }
*/
public static Long incrObject(Object key) { /**
Long result = null; * 判断一个key是否存在
try { *
result = jedisCluster.incr(SerializeUtils.serialize(key)); * @param key
} catch (Exception e) { * @return
LOGGER.warn("jedis缓存值自增1失败:" + e.getMessage(), e); */
} public static boolean exists(String key) {
return result; try {
} return jedisCluster.exists(key);
} catch (Exception e) {
/** LOGGER.warn("jedis判断key是否存在失败:" + e.getMessage(), e);
* 缓存值自减1 }
* return false;
* @param key }
* @return
*/ /**
public static Long decr(String key) { * 判断一个key是否存在
Long result = null; *
try { * @param key
result = jedisCluster.decr(key); * @return
} catch (Exception e) { */
LOGGER.warn("jedis缓存值自减1失败:" + e.getMessage(), e); public static boolean existsObject(Object key) {
} try {
return result; return jedisCluster.exists(SerializeUtils.serialize(key));
} } catch (Exception e) {
LOGGER.warn("jedis判断key是否存在失败:" + e.getMessage(), e);
/** }
* 缓存值自减1 return false;
* }
* @param key
* @return /**
*/ * 缓存值自增1
public static Long decrObject(Object key) { *
Long result = null; * @param key
try { * @return
result = jedisCluster.decr(SerializeUtils.serialize(key)); */
} catch (Exception e) { public static Long incr(String key) {
LOGGER.warn("jedis缓存值自减1失败:" + e.getMessage(), e); Long result = null;
} try {
return result; result = jedisCluster.incr(key);
} } catch (Exception e) {
LOGGER.warn("jedis缓存值自增1失败:" + e.getMessage(), e);
@Autowired }
public void setJedisCluster(JedisCluster jedisCluster) { return result;
JedisClusterUtils.jedisCluster = jedisCluster; }
}
/**
* 缓存值自增1
*
* @param key
* @return
*/
public static Long incrObject(Object key) {
Long result = null;
try {
result = jedisCluster.incr(SerializeUtils.serialize(key));
} catch (Exception e) {
LOGGER.warn("jedis缓存值自增1失败:" + e.getMessage(), e);
}
return result;
}
/**
* 缓存值自减1
*
* @param key
* @return
*/
public static Long decr(String key) {
Long result = null;
try {
result = jedisCluster.decr(key);
} catch (Exception e) {
LOGGER.warn("jedis缓存值自减1失败:" + e.getMessage(), e);
}
return result;
}
/**
* 缓存值自减1
*
* @param key
* @return
*/
public static Long decrObject(Object key) {
Long result = null;
try {
result = jedisCluster.decr(SerializeUtils.serialize(key));
} catch (Exception e) {
LOGGER.warn("jedis缓存值自减1失败:" + e.getMessage(), e);
}
return result;
}
@Autowired
public void setJedisCluster(JedisCluster jedisCluster) {
JedisClusterUtils.jedisCluster = jedisCluster;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment