Commit 3b0342a7 authored by lizhiheng's avatar lizhiheng

feat:新增一个取redis-key后缀的方法

parent 48635991
......@@ -38,7 +38,7 @@ allprojects {
}
group = "cn.com.duiba.boot"
version = "0.0.51"
version = "0.0.52"
}
subprojects {
......
......@@ -57,4 +57,24 @@ public class RedisBalanceKeyUtil {
}
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;
}
}
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