Commit ae8cf865 authored by lizhiheng's avatar lizhiheng

feat:版本号升级

parent 70674685
...@@ -38,7 +38,7 @@ allprojects { ...@@ -38,7 +38,7 @@ allprojects {
} }
group = "cn.com.duiba.boot" group = "cn.com.duiba.boot"
version = "0.0.53" version = "0.0.54"
} }
subprojects { subprojects {
......
...@@ -60,6 +60,26 @@ public class RedisBalanceKeyUtil { ...@@ -60,6 +60,26 @@ public class RedisBalanceKeyUtil {
return null; return null;
} }
/**
* 通过hash 然后取模获取指定的redis的suffix
*
* @param targetStr 目标字符串
* @return 返回指定节点对应的rediskey
*/
public static String getRedisBalance8keySuffix(String targetStr) {
String HashStr = DigestUtils.md5Hex(targetStr);
int targetHashValue = HashAlgorithm.dekHash(HashStr);
RedisBalance8KeyEnum[] values = RedisBalance8KeyEnum.values();
int mold = targetHashValue % (values.length);
for (RedisBalance8KeyEnum keyEnum : values) {
if (Objects.equals(keyEnum.order, mold)) {
String key = keyEnum.hashTag;
return StringUtils.join(keyEnum.order, START, key, END);
}
}
return null;
}
/** /**
* getRedisBalance8key的非hash版 * getRedisBalance8key的非hash版
* 从目标字符串中获取从左到右第一个数字并且取模得到redisKey * 从目标字符串中获取从左到右第一个数字并且取模得到redisKey
...@@ -88,16 +108,23 @@ public class RedisBalanceKeyUtil { ...@@ -88,16 +108,23 @@ public class RedisBalanceKeyUtil {
} }
/** /**
* 通过hash 然后取模获取指定的redis的suffix * getRedisBalance8keySuffix的非hash版
* 从目标字符串中获取从左到右第一个数字并且取模得到redisKey
* *
* @param targetStr 目标字符串 * @param targetStr 目标字符串
* @return 返回指定节点对应的rediskey * @return 返回指定节点对应的rediskey
*/ */
public static String getRedisBalance8keySuffix(String targetStr) { public static String getRedisSuffixByFirstNumMold(String targetStr) {
String HashStr = DigestUtils.md5Hex(targetStr); int randomNum = 0;
int targetHashValue = HashAlgorithm.dekHash(HashStr); for (int i = 0; i < targetStr.length(); i++) {
char c = targetStr.charAt(i);
if (c >= 48 && c <= 57) {
randomNum = c;
break;
}
}
RedisBalance8KeyEnum[] values = RedisBalance8KeyEnum.values(); RedisBalance8KeyEnum[] values = RedisBalance8KeyEnum.values();
int mold = targetHashValue % (values.length); int mold = randomNum % (values.length);
for (RedisBalance8KeyEnum keyEnum : values) { for (RedisBalance8KeyEnum keyEnum : values) {
if (Objects.equals(keyEnum.order, mold)) { if (Objects.equals(keyEnum.order, mold)) {
String key = keyEnum.hashTag; String key = keyEnum.hashTag;
...@@ -106,4 +133,5 @@ public class RedisBalanceKeyUtil { ...@@ -106,4 +133,5 @@ public class RedisBalanceKeyUtil {
} }
return null; return null;
} }
} }
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