Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sqlrest
Overview
Overview
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
comm
sqlrest
Commits
7b3af8b0
Commit
7b3af8b0
authored
Aug 20, 2025
by
inrgihc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
redis哨兵配置
parent
6b60243b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
14 deletions
+71
-14
README.md
+14
-0
sqlrest-cache/src/main/java/org/dromara/sqlrest/cache/SqlrestCacheConfiguration.java
+44
-9
sqlrest-cache/src/main/java/org/dromara/sqlrest/cache/redis/JedisClient.java
+3
-3
sqlrest-cache/src/main/java/org/dromara/sqlrest/cache/redis/RedisProperties.java
+10
-2
No files found.
README.md
View file @
7b3af8b0
...
...
@@ -200,10 +200,24 @@ sqlrest:
redis:
# 是否开启使用redis缓存,开启时需要配置下面对应的redis信息
enabled: true
# 哨兵模式下不用配置host
host: 127.0.0.1
# 哨兵模式下不用配置port
port: 6379
password: 123456
database: 0
pool:
min-idle: 1
max-idle: 8
max-active: 8
max-wait: -1
time-between-eviction-runs: -1
# 非哨兵模式下删除掉sentinel整个节点
sentinel:
# 哨兵模式下需要配置master
master: mymaster
# 哨兵模式下需要配置nodes
nodes: 127.0.0.1:26379,127.0.0.1:26380,127.0.0.1:26381
```
-
步骤3:如果为多主机节点部署,需要将sqlrest-release-x.x.x分发到其他主机节点上;如果为单机(单节点)部署可直接忽略本步骤。
...
...
sqlrest-cache/src/main/java/org/dromara/sqlrest/cache/SqlrestCacheConfiguration.java
View file @
7b3af8b0
...
...
@@ -9,20 +9,29 @@
/////////////////////////////////////////////////////////////
package
org
.
dromara
.
sqlrest
.
cache
;
import
com.hazelcast.config.Config
;
import
com.hazelcast.eureka.one.EurekaOneDiscoveryStrategyFactory
;
import
com.netflix.discovery.EurekaClient
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.Optional
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.dromara.sqlrest.cache.hazelcast.HazelcastCacheFactory
;
import
org.dromara.sqlrest.cache.redis.JedisClient
;
import
org.dromara.sqlrest.cache.redis.RedisCacheFactory
;
import
org.dromara.sqlrest.cache.redis.RedisProperties
;
import
org.dromara.sqlrest.common.consts.Constants
;
import
com.hazelcast.config.Config
;
import
com.hazelcast.eureka.one.EurekaOneDiscoveryStrategyFactory
;
import
com.netflix.discovery.EurekaClient
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
redis.clients.jedis.Jedis
;
import
redis.clients.jedis.JedisPool
;
import
redis.clients.jedis.JedisPoolConfig
;
import
redis.clients.jedis.JedisSentinelPool
;
import
redis.clients.jedis.util.Pool
;
@Configuration
public
class
SqlrestCacheConfiguration
{
...
...
@@ -59,7 +68,7 @@ public class SqlrestCacheConfiguration {
static
class
RedisCacheConfig
{
@Bean
public
JedisPool
jedisPool
(
RedisProperties
properties
)
{
public
Pool
<
Jedis
>
jedisPool
(
RedisProperties
properties
)
{
RedisProperties
.
Pool
pool
=
properties
.
getPool
();
JedisPoolConfig
poolConfig
=
new
JedisPoolConfig
();
poolConfig
.
setMaxTotal
(
pool
.
getMaxActive
());
...
...
@@ -71,14 +80,40 @@ public class SqlrestCacheConfiguration {
if
(
pool
.
getMaxWait
()
!=
null
)
{
poolConfig
.
setMaxWaitMillis
(
pool
.
getMaxWait
().
toMillis
());
}
return
new
JedisPool
(
poolConfig
,
properties
.
getHost
(),
properties
.
getPort
(),
(
int
)
properties
.
getTimeout
().
toMillis
(),
properties
.
getUsername
(),
properties
.
getPassword
(),
properties
.
getDatabase
(),
properties
.
isSsl
());
int
timeout
=
(
int
)
properties
.
getTimeout
().
toMillis
();
Set
<
String
>
sentinels
=
Optional
.
ofNullable
(
properties
.
getSentinel
())
.
map
(
s
->
Optional
.
ofNullable
(
s
.
getNodes
())
.
orElseGet
(
ArrayList:
:
new
)
.
stream
().
collect
(
Collectors
.
toSet
())
).
orElseGet
(
HashSet:
:
new
);
if
(
CollectionUtils
.
isNotEmpty
(
sentinels
))
{
return
new
JedisSentinelPool
(
properties
.
getSentinel
().
getMaster
(),
sentinels
,
poolConfig
,
timeout
,
properties
.
getUsername
(),
properties
.
getPassword
(),
properties
.
getDatabase
(),
properties
.
getClientName
());
}
else
{
return
new
JedisPool
(
poolConfig
,
properties
.
getHost
(),
properties
.
getPort
(),
timeout
,
properties
.
getUsername
(),
properties
.
getPassword
(),
properties
.
getDatabase
(),
properties
.
getClientName
(),
properties
.
isSsl
());
}
}
@Bean
public
JedisClient
jedisClient
(
JedisPool
jedisPool
)
{
public
JedisClient
jedisClient
(
Pool
<
Jedis
>
jedisPool
)
{
return
new
JedisClient
(
jedisPool
);
}
...
...
sqlrest-cache/src/main/java/org/dromara/sqlrest/cache/redis/JedisClient.java
View file @
7b3af8b0
...
...
@@ -12,13 +12,13 @@ package org.dromara.sqlrest.cache.redis;
import
java.util.function.Consumer
;
import
java.util.function.Function
;
import
redis.clients.jedis.Jedis
;
import
redis.clients.jedis.
Jedis
Pool
;
import
redis.clients.jedis.
util.
Pool
;
public
class
JedisClient
{
private
JedisPool
jedisPool
;
private
Pool
<
Jedis
>
jedisPool
;
public
JedisClient
(
JedisPool
jedisPool
)
{
public
JedisClient
(
Pool
<
Jedis
>
jedisPool
)
{
this
.
jedisPool
=
jedisPool
;
}
...
...
sqlrest-cache/src/main/java/org/dromara/sqlrest/cache/redis/RedisProperties.java
View file @
7b3af8b0
...
...
@@ -10,6 +10,7 @@
package
org
.
dromara
.
sqlrest
.
cache
.
redis
;
import
java.time.Duration
;
import
java.util.List
;
import
lombok.Data
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
...
...
@@ -27,16 +28,23 @@ public class RedisProperties {
private
Duration
timeBetweenEvictionRuns
;
}
@Data
public
static
class
Sentinel
{
private
String
master
;
private
List
<
String
>
nodes
;
}
private
boolean
enabled
=
false
;
private
int
database
=
0
;
private
String
host
=
"127.0.0.1"
;
private
int
port
=
6379
;
private
String
username
;
private
String
password
;
private
int
port
=
6379
;
private
boolean
ssl
=
false
;
private
Duration
timeout
=
Duration
.
ofSeconds
(
1
);
private
Duration
connectTimeout
=
Duration
.
ofSeconds
(
1
);
private
String
clientName
=
"sqlrest"
;
private
Pool
pool
=
new
Pool
();
private
Sentinel
sentinel
=
new
Sentinel
();
}
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