CacheKeyEnum.java
1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
*
*/
package com.yohoufo.user.cache;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import org.apache.commons.lang3.StringUtils;
import java.util.concurrent.TimeUnit;
/**
* 描述:
*
* @author craig.qin 2018年9月17日
*/
public enum CacheKeyEnum {
// user - passport -authorize
AUTHORIZE_INFO_KEY("ufo:user:authorizeInfo:","实名认证信息", 2, TimeUnit.HOURS),
ZHI_MA_CERT_KEY("ufo:user:zhiMaCert:","芝麻认证信息", 2, TimeUnit.HOURS),
STORED_SELLER_KEY("ufo:user:storedSeller:","商家入驻信息", 2, TimeUnit.HOURS),
USER_PRODUCT_FAVORITE_ZSET_KEY("ufo:user:product:favorite:","用户商品收藏集合", 180, TimeUnit.DAYS),
SUPER_ENTRY_SELLER_LIST("ufo:user:superEntrySeller:list","超级入驻商家集合", 1, TimeUnit.HOURS)
;
// 缓存的key
private String cacheKey;
private String desc;
// 默认的过期时间
private int defaultExpireTime;
// 缓存时间单位
private TimeUnit timeUnit;
CacheKeyEnum(String cacheKey, String desc, int defaultExpireTime, TimeUnit timeUnit) {
this.cacheKey = cacheKey;
this.desc = desc;
this.defaultExpireTime = defaultExpireTime;
this.timeUnit = timeUnit;
}
/**
* 获取该枚举的信息
*
* @param key
* @return
*/
public static CacheKeyEnum getEnumByKey(String key) {
if (StringUtils.isEmpty(key)) {
return null;
}
for (CacheKeyEnum e : values()) {
if (key.equalsIgnoreCase(e.name())) {
return e;
}
}
return null;
}
public String getCacheKey() {
return cacheKey;
}
public int getDefaultExpireTime() {
return defaultExpireTime;
}
public TimeUnit getTimeUnit() {
return timeUnit;
}
public String getDesc() {
return desc;
}
public RedisKeyBuilder getKey(){
return RedisKeyBuilder.newInstance().appendFixed(cacheKey);
}
}