Commit f17bb6ac authored by lizhiheng's avatar lizhiheng

feat:新增个方法(根据字符串第一个字符的asc码取模)

parent ae8cf865
......@@ -38,7 +38,7 @@ allprojects {
}
group = "cn.com.duiba.boot"
version = "0.0.54"
version = "0.0.56"
}
subprojects {
......
......@@ -134,4 +134,25 @@ public class RedisBalanceKeyUtil {
return null;
}
/**
* getRedisBalance8keySuffix的非hash版
* 从目标字符串中获取从左到右第一个数字或字母并且取模得到redisKey
*
* @param targetStr 目标字符串
* @return 返回指定节点对应的rediskey
*/
public static String getRedisSuffixByFirstCharacterMold(String targetStr) {
int randomNum = targetStr.charAt(0);
RedisBalance8KeyEnum[] values = RedisBalance8KeyEnum.values();
int mold = randomNum % (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