Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
spring-boot-starter-dsp
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
shenjiaqing
spring-boot-starter-dsp
Commits
ae8cf865
Commit
ae8cf865
authored
Jun 23, 2022
by
lizhiheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:版本号升级
parent
70674685
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
6 deletions
+34
-6
build.gradle
build.gradle
+1
-1
RedisBalanceKeyUtil.java
...iba/spring/boot/starter/dsp/util/RedisBalanceKeyUtil.java
+33
-5
No files found.
build.gradle
View file @
ae8cf865
...
...
@@ -38,7 +38,7 @@ allprojects {
}
group
=
"cn.com.duiba.boot"
version
=
"0.0.5
3
"
version
=
"0.0.5
4
"
}
subprojects
{
...
...
spring-boot-starter-dsp-util/src/main/java/cn/com/duiba/spring/boot/starter/dsp/util/RedisBalanceKeyUtil.java
View file @
ae8cf865
...
...
@@ -60,6 +60,26 @@ 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
;
}
/**
* getRedisBalance8key的非hash版
* 从目标字符串中获取从左到右第一个数字并且取模得到redisKey
...
...
@@ -88,16 +108,23 @@ public class RedisBalanceKeyUtil {
}
/**
* 通过hash 然后取模获取指定的redis的suffix
* getRedisBalance8keySuffix的非hash版
* 从目标字符串中获取从左到右第一个数字并且取模得到redisKey
*
* @param targetStr 目标字符串
* @return 返回指定节点对应的rediskey
*/
public
static
String
getRedisBalance8keySuffix
(
String
targetStr
)
{
String
HashStr
=
DigestUtils
.
md5Hex
(
targetStr
);
int
targetHashValue
=
HashAlgorithm
.
dekHash
(
HashStr
);
public
static
String
getRedisSuffixByFirstNumMold
(
String
targetStr
)
{
int
randomNum
=
0
;
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
();
int
mold
=
targetHashValue
%
(
values
.
length
);
int
mold
=
randomNum
%
(
values
.
length
);
for
(
RedisBalance8KeyEnum
keyEnum
:
values
)
{
if
(
Objects
.
equals
(
keyEnum
.
order
,
mold
))
{
String
key
=
keyEnum
.
hashTag
;
...
...
@@ -106,4 +133,5 @@ public class RedisBalanceKeyUtil {
}
return
null
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment