更换缓存前缀 双冒号太别扭了 密集恐惧症

v1.4.1
Parker 5 years ago
parent 6cb7589feb
commit 955d640b93

@ -25,12 +25,12 @@ package org.opsli.common.constants;
public interface DictConstants { public interface DictConstants {
/** 缓存前缀 NAME */ /** 缓存前缀 NAME */
String CACHE_PREFIX_NAME = "dict::name::"; String CACHE_PREFIX_NAME = "dict:name:";
/** 缓存前缀 VALUE*/ /** 缓存前缀 VALUE*/
String CACHE_PREFIX_VALUE = "dict::value::"; String CACHE_PREFIX_VALUE = "dict:value:";
/** 缓存前缀 LIST*/ /** 缓存前缀 LIST*/
String CACHE_PREFIX_LIST = "dict::list::"; String CACHE_PREFIX_LIST = "dict:list:";
} }

@ -110,7 +110,7 @@ public abstract class BaseRestController <T extends BaseEntity, E extends ApiWra
// 如果开启缓存 先从缓存读 // 如果开启缓存 先从缓存读
if(hotDataFlag){ if(hotDataFlag){
// 缓存Key // 缓存Key
String cacheKey = CacheConstants.HOT_DATA_PREFIX +"::"+ id; String cacheKey = CacheConstants.HOT_DATA_PREFIX +":"+ id;
model = WrapperUtil.transformInstance( model = WrapperUtil.transformInstance(
CacheUtil.getTimed(entityClazz, cacheKey) CacheUtil.getTimed(entityClazz, cacheKey)

@ -299,7 +299,7 @@ public class CacheUtil {
if(isSaveLocal){ if(isSaveLocal){
// 获得缓存Json // 获得缓存Json
cacheJson = ehCachePlugin.get(CacheConstants.EHCACHE_SPACE, cacheJson = ehCachePlugin.get(CacheConstants.EHCACHE_SPACE,
cacheKey +"::"+ field, JSONObject.class); cacheKey +":"+ field, JSONObject.class);
if(cacheJson != null){ if(cacheJson != null){
return cacheJson.get(JSON_KEY); return cacheJson.get(JSON_KEY);
} }
@ -312,7 +312,7 @@ public class CacheUtil {
if(isSaveLocal){ if(isSaveLocal){
//存入EhCache //存入EhCache
ehCachePlugin.put(CacheConstants.EHCACHE_SPACE, ehCachePlugin.put(CacheConstants.EHCACHE_SPACE,
cacheKey + "::" + field, cacheJson); cacheKey + ":" + field, cacheJson);
} }
} }
@ -474,7 +474,7 @@ public class CacheUtil {
String cacheKey = CacheUtil.handleKey(CacheType.EDEN_HASH, key); String cacheKey = CacheUtil.handleKey(CacheType.EDEN_HASH, key);
// 删除 EhCache // 删除 EhCache
boolean ehcacheRet = ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE,cacheKey +"::"+ field); boolean ehcacheRet = ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE,cacheKey +":"+ field);
if(ehcacheRet){ if(ehcacheRet){
count--; count--;
} }
@ -504,7 +504,7 @@ public class CacheUtil {
public static boolean putNilFlag(String key) { public static boolean putNilFlag(String key) {
try { try {
// 处理缓存 key // 处理缓存 key
String cacheKey = CacheUtil.handleKey(NIL_FLAG_PREFIX + "::" + key); String cacheKey = CacheUtil.handleKey(NIL_FLAG_PREFIX + ":" + key);
// 存入Redis // 存入Redis
return redisPlugin.put(cacheKey, 1, TTL_NIL_DATA_TIME); return redisPlugin.put(cacheKey, 1, TTL_NIL_DATA_TIME);
}catch (Exception e){ }catch (Exception e){
@ -523,7 +523,7 @@ public class CacheUtil {
public static boolean delNilFlag(String key) { public static boolean delNilFlag(String key) {
try { try {
// 处理缓存 key // 处理缓存 key
String cacheKey = CacheUtil.handleKey(NIL_FLAG_PREFIX + "::" + key); String cacheKey = CacheUtil.handleKey(NIL_FLAG_PREFIX + ":" + key);
// 删除Redis // 删除Redis
return redisPlugin.del(cacheKey); return redisPlugin.del(cacheKey);
}catch (Exception e){ }catch (Exception e){
@ -543,7 +543,7 @@ public class CacheUtil {
public static boolean hasNilFlag(String key) { public static boolean hasNilFlag(String key) {
try { try {
// 处理缓存 key // 处理缓存 key
String cacheKey = CacheUtil.handleKey(NIL_FLAG_PREFIX + "::" + key); String cacheKey = CacheUtil.handleKey(NIL_FLAG_PREFIX + ":" + key);
// 判断Redis 是否 包含当前Nil值 // 判断Redis 是否 包含当前Nil值
return redisPlugin.get(cacheKey) != null; return redisPlugin.get(cacheKey) != null;
}catch (Exception e){ }catch (Exception e){
@ -571,7 +571,7 @@ public class CacheUtil {
* @return String * @return String
*/ */
public static String handleKey(CacheType cacheType, String key){ public static String handleKey(CacheType cacheType, String key){
return PREFIX_NAME + cacheType.getName() + "::" + return PREFIX_NAME + cacheType.getName() + ":" +
key; key;
} }
@ -649,7 +649,7 @@ public class CacheUtil {
public void init(CacheProperties cacheProperties){ public void init(CacheProperties cacheProperties){
if(cacheProperties != null){ if(cacheProperties != null){
// 获得 超级管理员 // 获得 超级管理员
CacheUtil.PREFIX_NAME = Convert.toStr(cacheProperties.getPrefix(), "opsli") + "::"; CacheUtil.PREFIX_NAME = Convert.toStr(cacheProperties.getPrefix(), "opsli") + ":";
} }
} }

@ -85,9 +85,9 @@ public class DictHandler implements RedisPushSubHandler{
// 解析 key // 解析 key
String ehKeyByName = CacheUtil.handleKey(CacheType.EDEN_HASH, DictConstants.CACHE_PREFIX_NAME + String ehKeyByName = CacheUtil.handleKey(CacheType.EDEN_HASH, DictConstants.CACHE_PREFIX_NAME +
dictWrapperModel.getTypeCode() + "::" + dictWrapperModel.getDictName()); dictWrapperModel.getTypeCode() + ":" + dictWrapperModel.getDictName());
String ehKeyByValue = CacheUtil.handleKey(CacheType.EDEN_HASH, DictConstants.CACHE_PREFIX_VALUE + String ehKeyByValue = CacheUtil.handleKey(CacheType.EDEN_HASH, DictConstants.CACHE_PREFIX_VALUE +
dictWrapperModel.getTypeCode() + "::" + dictWrapperModel.getDictValue()); dictWrapperModel.getTypeCode() + ":" + dictWrapperModel.getDictValue());
// 缓存更新 // 缓存更新
if(CacheHandleType.UPDATE == type){ if(CacheHandleType.UPDATE == type){

@ -55,7 +55,7 @@ public class HotDataHandler implements RedisPushSubHandler{
} }
// 拼装缓存key // 拼装缓存key
String cacheName = CacheUtil.handleKey(CacheConstants.HOT_DATA_PREFIX +"::"+ key); String cacheName = CacheUtil.handleKey(CacheConstants.HOT_DATA_PREFIX +":"+ key);
if(CacheHandleType.UPDATE == type){ if(CacheHandleType.UPDATE == type){
ehCachePlugin.put(CacheConstants.EHCACHE_SPACE, cacheName, value); ehCachePlugin.put(CacheConstants.EHCACHE_SPACE, cacheName, value);

@ -93,7 +93,7 @@ public class CacheDataAop {
for (CacheDataEntity cacheDataEntity : cacheDataEntityList) { for (CacheDataEntity cacheDataEntity : cacheDataEntityList) {
// 更新缓存数据 // 更新缓存数据
// 热点数据 // 热点数据
boolean putRet = CacheUtil.put(CacheConstants.HOT_DATA_PREFIX +"::"+ cacheDataEntity.getKey(), boolean putRet = CacheUtil.put(CacheConstants.HOT_DATA_PREFIX +":"+ cacheDataEntity.getKey(),
returnValue); returnValue);
if(putRet){ if(putRet){
// 广播缓存数据 - 通知其他服务器同步数据 // 广播缓存数据 - 通知其他服务器同步数据
@ -143,7 +143,7 @@ public class CacheDataAop {
for (CacheDataEntity cacheDataEntity : cacheDataEntityList) { for (CacheDataEntity cacheDataEntity : cacheDataEntityList) {
// 更新缓存数据 - 删除缓存 // 更新缓存数据 - 删除缓存
boolean delRet = CacheUtil.del(CacheConstants.HOT_DATA_PREFIX +"::"+ cacheDataEntity.getKey()); boolean delRet = CacheUtil.del(CacheConstants.HOT_DATA_PREFIX +":"+ cacheDataEntity.getKey());
if(delRet){ if(delRet){
// 广播缓存数据 - 通知其他服务器同步数据 // 广播缓存数据 - 通知其他服务器同步数据
redisPlugin.sendMessage( redisPlugin.sendMessage(

@ -32,7 +32,7 @@ public class RedisCacheManager implements CacheManager {
/** /**
* The Redis key prefix for caches * The Redis key prefix for caches
*/ */
public static final String DEFAULT_CACHE_KEY_PREFIX = "shiro::cache::"; public static final String DEFAULT_CACHE_KEY_PREFIX = "shiro:cache:";
private String keyPrefix = DEFAULT_CACHE_KEY_PREFIX; private String keyPrefix = DEFAULT_CACHE_KEY_PREFIX;
public static final String DEFAULT_PRINCIPAL_ID_FIELD_NAME = "authCacheKey or id"; public static final String DEFAULT_PRINCIPAL_ID_FIELD_NAME = "authCacheKey or id";
@ -45,7 +45,7 @@ public class RedisCacheManager implements CacheManager {
Cache cache = caches.get(name); Cache cache = caches.get(name);
if (cache == null) { if (cache == null) {
cache = new RedisCache<K, V>(redisManager,keyPrefix + name + "::", expire, principalIdFieldName); cache = new RedisCache<K, V>(redisManager,keyPrefix + name + ":", expire, principalIdFieldName);
caches.put(name, cache); caches.put(name, cache);
} }
return cache; return cache;

@ -25,10 +25,10 @@ package org.opsli.core.security.shiro.utils;
public class RedisKeys { public class RedisKeys {
public static String getSysConfigKey(String key){ public static String getSysConfigKey(String key){
return "system::config::" + key; return "system:config:" + key;
} }
public static String getShiroSessionKey(String key){ public static String getShiroSessionKey(String key){
return "sessionid::" + key; return "sessionid:" + key;
} }
} }

@ -58,7 +58,7 @@ public class CaptchaUtil {
private static final List<CaptchaStrategy> CAPTCHA_STRATEGY_LIST; private static final List<CaptchaStrategy> CAPTCHA_STRATEGY_LIST;
/** 缓存前缀 */ /** 缓存前缀 */
private static final String PREFIX = "temp::captcha::"; private static final String PREFIX = "temp:captcha:";
/** 默认验证码保存 5 分钟 */ /** 默认验证码保存 5 分钟 */
private static final int TIME_OUT = 300; private static final int TIME_OUT = 300;
/** Redis插件 */ /** Redis插件 */

@ -72,7 +72,7 @@ public class DictUtil {
// 缓存Key // 缓存Key
String cacheKey = DictConstants.CACHE_PREFIX_VALUE + typeCode; String cacheKey = DictConstants.CACHE_PREFIX_VALUE + typeCode;
// 缓存Key + VALUE // 缓存Key + VALUE
String cacheKeyVal = cacheKey + "::" + dictValue; String cacheKeyVal = cacheKey + ":" + dictValue;
// 字典名称 // 字典名称
String dictName = null; String dictName = null;
@ -152,7 +152,7 @@ public class DictUtil {
// 缓存Key // 缓存Key
String cacheKey = DictConstants.CACHE_PREFIX_NAME + typeCode; String cacheKey = DictConstants.CACHE_PREFIX_NAME + typeCode;
// 缓存Key + VALUE // 缓存Key + VALUE
String cacheKeyVal = cacheKey + "::" + dictName; String cacheKeyVal = cacheKey + ":" + dictName;
// 字典值 // 字典值
String dictValue = null; String dictValue = null;
@ -369,9 +369,9 @@ public class DictUtil {
} }
boolean hasNilFlagByName = CacheUtil.hasNilFlag(DictConstants.CACHE_PREFIX_NAME + boolean hasNilFlagByName = CacheUtil.hasNilFlag(DictConstants.CACHE_PREFIX_NAME +
model.getTypeCode() + "::" + model.getDictName()); model.getTypeCode() + ":" + model.getDictName());
boolean hasNilFlagByValue = CacheUtil.hasNilFlag(DictConstants.CACHE_PREFIX_VALUE + boolean hasNilFlagByValue = CacheUtil.hasNilFlag(DictConstants.CACHE_PREFIX_VALUE +
model.getTypeCode() + "::" + model.getDictValue()); model.getTypeCode() + ":" + model.getDictValue());
DictWrapper dictByName = CacheUtil.getHash(DictWrapper.class, DictWrapper dictByName = CacheUtil.getHash(DictWrapper.class,
DictConstants.CACHE_PREFIX_NAME + model.getTypeCode(), DictConstants.CACHE_PREFIX_NAME + model.getTypeCode(),
@ -386,7 +386,7 @@ public class DictUtil {
count++; count++;
// 清除空拦截 // 清除空拦截
boolean tmp = CacheUtil.delNilFlag(DictConstants.CACHE_PREFIX_NAME + boolean tmp = CacheUtil.delNilFlag(DictConstants.CACHE_PREFIX_NAME +
model.getTypeCode() + "::" + model.getDictName()); model.getTypeCode() + ":" + model.getDictName());
if(tmp){ if(tmp){
count--; count--;
} }
@ -396,7 +396,7 @@ public class DictUtil {
count++; count++;
// 清除空拦截 // 清除空拦截
boolean tmp = CacheUtil.delNilFlag(DictConstants.CACHE_PREFIX_VALUE + boolean tmp = CacheUtil.delNilFlag(DictConstants.CACHE_PREFIX_VALUE +
model.getTypeCode() + "::" + model.getDictValue()); model.getTypeCode() + ":" + model.getDictValue());
if(tmp){ if(tmp){
count--; count--;
} }

@ -45,7 +45,7 @@ import static org.opsli.common.constants.OrderConstants.UTIL_ORDER;
public class MenuUtil { public class MenuUtil {
/** 前缀 */ /** 前缀 */
public static final String PREFIX_CODE = "menu::code::"; public static final String PREFIX_CODE = "menu:code:";
/** Redis插件 */ /** Redis插件 */

@ -45,7 +45,7 @@ import static org.opsli.common.constants.OrderConstants.UTIL_ORDER;
public class OrgUtil { public class OrgUtil {
/** 前缀 */ /** 前缀 */
public static final String PREFIX_CODE = "org::userId::"; public static final String PREFIX_CODE = "org:userId:";
/** Redis插件 */ /** Redis插件 */

@ -48,7 +48,7 @@ public class SearchHisUtil {
/** 搜索历史缓存数据KEY */ /** 搜索历史缓存数据KEY */
private static final int DEFAULT_COUNT = 10; private static final int DEFAULT_COUNT = 10;
private static final String CACHE_PREFIX = "his::username::"; private static final String CACHE_PREFIX = "his:username:";
/** Redis插件 */ /** Redis插件 */
private static RedisPlugin redisPlugin; private static RedisPlugin redisPlugin;
@ -71,7 +71,7 @@ public class SearchHisUtil {
// 获得当前用户 // 获得当前用户
UserModel user = UserUtil.getUser(); UserModel user = UserUtil.getUser();
String cacheKey = CacheUtil.getPrefixName() + CACHE_PREFIX + user.getUsername() + "::" + key; String cacheKey = CacheUtil.getPrefixName() + CACHE_PREFIX + user.getUsername() + ":" + key;
return redisPlugin.zReverseRange(cacheKey, 0, count - 1); return redisPlugin.zReverseRange(cacheKey, 0, count - 1);
} }
@ -97,7 +97,7 @@ public class SearchHisUtil {
} }
String cacheKey = CacheUtil.getPrefixName() + CACHE_PREFIX + user.getUsername() + "::" + key; String cacheKey = CacheUtil.getPrefixName() + CACHE_PREFIX + user.getUsername() + ":" + key;
String val = values[0]; String val = values[0];
// 记录 // 记录

@ -45,7 +45,7 @@ import static org.opsli.common.constants.OrderConstants.UTIL_ORDER;
public class TenantUtil { public class TenantUtil {
/** 前缀 */ /** 前缀 */
public static final String PREFIX_CODE = "tenant::id::"; public static final String PREFIX_CODE = "tenant:id:";
/** Redis插件 */ /** Redis插件 */

@ -61,11 +61,11 @@ public class UserTokenUtil {
/** token 缓存名 */ /** token 缓存名 */
public static final String TOKEN_NAME = TokenConstants.ACCESS_TOKEN; public static final String TOKEN_NAME = TokenConstants.ACCESS_TOKEN;
/** 缓存前缀 */ /** 缓存前缀 */
private static final String TICKET_PREFIX = "ticket::"; private static final String TICKET_PREFIX = "ticket:";
/** 账号失败次数 */ /** 账号失败次数 */
public static final String ACCOUNT_SLIP_COUNT_PREFIX = "account::slip::count::"; public static final String ACCOUNT_SLIP_COUNT_PREFIX = "account:slip:count:";
/** 账号失败锁定KEY */ /** 账号失败锁定KEY */
public static final String ACCOUNT_SLIP_LOCK_PREFIX = "account::slip::lock::"; public static final String ACCOUNT_SLIP_LOCK_PREFIX = "account:slip:lock:";
/** 限制登录数量 -1 为无限大 */ /** 限制登录数量 -1 为无限大 */
public static final int ACCOUNT_LIMIT_INFINITE = -1; public static final int ACCOUNT_LIMIT_INFINITE = -1;
/** 登录配置信息 */ /** 登录配置信息 */

@ -55,11 +55,11 @@ import static org.opsli.common.constants.OrderConstants.UTIL_ORDER;
public class UserUtil { public class UserUtil {
/** 前缀 */ /** 前缀 */
public static final String PREFIX_ID = "userId::"; public static final String PREFIX_ID = "userId:";
public static final String PREFIX_ID_ROLES = "userId::roles::"; public static final String PREFIX_ID_ROLES = "userId:roles:";
public static final String PREFIX_ID_PERMISSIONS = "userId::permissions::"; public static final String PREFIX_ID_PERMISSIONS = "userId:permissions:";
public static final String PREFIX_ID_MENUS = "userId::menus::"; public static final String PREFIX_ID_MENUS = "userId:menus:";
public static final String PREFIX_USERNAME = "username::"; public static final String PREFIX_USERNAME = "username:";
/** Redis插件 */ /** Redis插件 */

@ -27,7 +27,7 @@ import java.util.concurrent.atomic.AtomicInteger;
*/ */
public class RedisLock { public class RedisLock {
private static final String LOCK_PREFIX = "lock::"; private static final String LOCK_PREFIX = "lock:";
/** 锁名称 */ /** 锁名称 */
private String lockName; private String lockName;

@ -53,7 +53,7 @@ import java.util.List;
public class RedisLockImpl implements RedisLockPlugins { public class RedisLockImpl implements RedisLockPlugins {
/** 锁前缀 */ /** 锁前缀 */
private static final String LOCK_NAME_PREFIX = "lock::"; private static final String LOCK_NAME_PREFIX = "lock:";
@Autowired @Autowired
private RedisPlugin redisPlugin; private RedisPlugin redisPlugin;

@ -11,7 +11,7 @@ package org.opsli.plugins.redis.pushsub.receiver;
*/ */
public abstract class BaseReceiver { public abstract class BaseReceiver {
public static final String BASE_CHANNEL = "listener::msg::"; public static final String BASE_CHANNEL = "listener:msg:";
private final String channel; private final String channel;
public BaseReceiver(String channel){ public BaseReceiver(String channel){

@ -17,7 +17,7 @@ import java.util.concurrent.TimeUnit;
@Slf4j @Slf4j
public class RedissonLock { public class RedissonLock {
private static final String PREFIX = "lock::"; private static final String PREFIX = "lock:";
private RedissonManager redissonManager; private RedissonManager redissonManager;
private RedissonClient redisson; private RedissonClient redisson;

@ -17,7 +17,7 @@ public @interface DistributedLock {
/** /**
* *
*/ */
String value() default "opsli::redisson"; String value() default "opsli:redisson";
/** /**
* *

Loading…
Cancel
Save