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
aea678c1
Commit
aea678c1
authored
Jun 23, 2022
by
lizhiheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:新增方法(对目标字符串中对第一个数字进行取模从而获取到分片key)
parent
3b0342a7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
3 deletions
+32
-3
RedisBalanceKeyUtil.java
...iba/spring/boot/starter/dsp/util/RedisBalanceKeyUtil.java
+32
-3
No files found.
spring-boot-starter-dsp-util/src/main/java/cn/com/duiba/spring/boot/starter/dsp/util/RedisBalanceKeyUtil.java
View file @
aea678c1
package
cn
.
com
.
duiba
.
spring
.
boot
.
starter
.
dsp
.
util
;
package
cn
.
com
.
duiba
.
spring
.
boot
.
starter
.
dsp
.
util
;
import
cn.com.duiba.spring.boot.starter.dsp.enums.RedisBalance8KeyEnum
;
import
cn.com.duiba.spring.boot.starter.dsp.enums.RedisBalance8KeyEnum
;
import
com.google.common.base.Stopwatch
;
import
org.apache.commons.codec.digest.DigestUtils
;
import
org.apache.commons.codec.digest.DigestUtils
;
import
org.apache.commons.lang.time.StopWatch
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
java.util.
ArrayList
;
import
java.util.
*
;
import
java.util.
Lis
t
;
import
java.util.
concurrent.TimeUni
t
;
import
java.util.
Objects
;
import
java.util.
stream.IntStream
;
/**
/**
* @author jiangyangyang
* @author jiangyangyang
...
@@ -58,6 +60,33 @@ public class RedisBalanceKeyUtil {
...
@@ -58,6 +60,33 @@ public class RedisBalanceKeyUtil {
return
null
;
return
null
;
}
}
/**
* getRedisBalance8key的非hash版
* 从目标字符串中获取从左到右第一个数字并且取模得到redisKey
*
* @param targetStr 目标字符串
* @return 返回指定节点对应的rediskey
*/
public
static
String
getRedisKeyByFirstNumMold
(
String
prefix
,
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
=
randomNum
%
(
values
.
length
);
for
(
RedisBalance8KeyEnum
keyEnum
:
values
)
{
if
(
Objects
.
equals
(
keyEnum
.
order
,
mold
))
{
String
key
=
keyEnum
.
hashTag
;
return
StringUtils
.
join
(
prefix
,
"_"
,
keyEnum
.
order
,
START
,
key
,
END
);
}
}
return
null
;
}
/**
/**
* 通过hash 然后取模获取指定的redis的suffix
* 通过hash 然后取模获取指定的redis的suffix
*
*
...
...
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