Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
Details
Activity
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
项目统一框架
amos-boot-biz
Commits
5cd4aebd
Commit
5cd4aebd
authored
Jan 31, 2023
by
tangwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改redis连接
parent
377045ac
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
23 deletions
+33
-23
RedissonConfig.java
...java/com/yeejoin/amos/boot/biz/config/RedissonConfig.java
+33
-23
No files found.
amos-boot-biz-common/src/main/java/com/yeejoin/amos/boot/biz/config/RedissonConfig.java
View file @
5cd4aebd
...
...
@@ -23,6 +23,8 @@ import java.util.List;
public
class
RedissonConfig
{
@Autowired
private
RedisConfigProperties
redisConfigProperties
;
private
volatile
static
RedissonClient
redissonClient
;
/**
* 集群模式的 redisson 客户端
*
...
...
@@ -32,31 +34,39 @@ public class RedissonConfig {
@ConditionalOnProperty
(
name
=
"spring.redis.mode"
,
havingValue
=
"cluster"
)
public
RedissonClient
redissonClient
()
{
//redisson版本是3.5,集群的ip前面要加上“redis://”,不然会报错,3.2版本可不加
List
<
String
>
clusterNodes
=
new
ArrayList
<>();
System
.
out
.
println
(
"cluster redisProperties:"
+
redisConfigProperties
.
getCluster
().
toString
());
for
(
int
i
=
0
;
i
<
redisConfigProperties
.
getCluster
().
getNodes
().
size
();
i
++)
{
clusterNodes
.
add
(
"redis://"
+
redisConfigProperties
.
getCluster
().
getNodes
().
get
(
i
));
}
Config
config
=
new
Config
();
if
(
redissonClient
==
null
){
synchronized
(
RedissonConfig
.
class
){
if
(
redissonClient
==
null
){
List
<
String
>
clusterNodes
=
new
ArrayList
<>();
System
.
out
.
println
(
"cluster redisProperties:"
+
redisConfigProperties
.
getCluster
().
toString
());
for
(
int
i
=
0
;
i
<
redisConfigProperties
.
getCluster
().
getNodes
().
size
();
i
++)
{
clusterNodes
.
add
(
"redis://"
+
redisConfigProperties
.
getCluster
().
getNodes
().
get
(
i
));
}
Config
config
=
new
Config
();
ClusterServersConfig
clusterServersConfig
=
config
.
useClusterServers
()
//设置集群扫描时间
.
setScanInterval
(
5000
)
// 集群状态扫描间隔时间,单位是毫秒
.
setTimeout
(
30000
)
//主节点线程池数量
.
setMasterConnectionPoolSize
(
20
)
//从节点线程池数量
.
setSlaveConnectionPoolSize
(
20
)
.
setIdleConnectionTimeout
(
10000
)
.
setSlaveConnectionMinimumIdleSize
(
20
)
.
setMasterConnectionMinimumIdleSize
(
20
)
.
addNodeAddress
(
clusterNodes
.
toArray
(
new
String
[
clusterNodes
.
size
()]));
clusterServersConfig
.
setCheckSlotsCoverage
(
false
);
// 设置密码
if
(
StringUtils
.
isNotBlank
(
redisConfigProperties
.
getPassword
()))
{
clusterServersConfig
.
setPassword
(
redisConfigProperties
.
getPassword
());
}
redissonClient
=
Redisson
.
create
(
config
);
}
}
ClusterServersConfig
clusterServersConfig
=
config
.
useClusterServers
()
//设置集群扫描时间
.
setScanInterval
(
5000
)
// 集群状态扫描间隔时间,单位是毫秒
.
setTimeout
(
30000
)
//主节点线程池数量
.
setMasterConnectionPoolSize
(
20
)
//从节点线程池数量
.
setSlaveConnectionPoolSize
(
20
)
.
setIdleConnectionTimeout
(
10000
)
.
setSlaveConnectionMinimumIdleSize
(
20
)
.
setMasterConnectionMinimumIdleSize
(
20
)
.
addNodeAddress
(
clusterNodes
.
toArray
(
new
String
[
clusterNodes
.
size
()]));
clusterServersConfig
.
setCheckSlotsCoverage
(
false
);
// 设置密码
if
(
StringUtils
.
isNotBlank
(
redisConfigProperties
.
getPassword
()))
{
clusterServersConfig
.
setPassword
(
redisConfigProperties
.
getPassword
());
}
RedissonClient
redissonClient
=
Redisson
.
create
(
config
);
return
redissonClient
;
}
...
...
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