Merge pull request #2983 from anjia0532/starter-use-application

feat(starter): support spring config server/appolo/nacos
pull/3097/head
Nikita Koksharov 4 years ago committed by GitHub
commit 004b941981
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -43,23 +43,62 @@ Downgrade `redisson-spring-data` module if necessary to support required Spring
Common spring boot settings or Redisson settings could be used.
```properties
```yaml
# common spring boot settings
spring.redis.database=
spring.redis.host=
spring.redis.port=
spring.redis.password=
spring.redis.ssl=
spring.redis.timeout=
spring.redis.cluster.nodes=
spring.redis.sentinel.master=
spring.redis.sentinel.nodes=
spring:
redis:
database:
host:
port:
password:
ssl:
timeout:
cluster:
nodes:
sentinel:
master:
nodes:
# Redisson settings
#path to config - redisson.yaml
redisson:
file: classpath:redisson.yaml
config: |
clusterServersConfig:
idleConnectionTimeout: 10000
connectTimeout: 10000
timeout: 3000
retryAttempts: 3
retryInterval: 1500
failedSlaveReconnectionInterval: 3000
failedSlaveCheckInterval: 60000
password: null
subscriptionsPerConnection: 5
clientName: null
loadBalancer: !<org.redisson.connection.balancer.RoundRobinLoadBalancer> {}
subscriptionConnectionMinimumIdleSize: 1
subscriptionConnectionPoolSize: 50
slaveConnectionMinimumIdleSize: 24
slaveConnectionPoolSize: 64
masterConnectionMinimumIdleSize: 24
masterConnectionPoolSize: 64
readMode: "SLAVE"
subscriptionMode: "SLAVE"
nodeAddresses:
- "redis://127.0.0.1:7004"
- "redis://127.0.0.1:7001"
- "redis://127.0.0.1:7000"
scanInterval: 1000
pingConnectionInterval: 0
keepAlive: false
tcpNoDelay: false
threads: 16
nettyThreads: 32
codec: !<org.redisson.codec.FstCodec> {}
transportMode: "NIO"
# Redisson settings
#path to config - redisson.yaml
spring.redis.redisson.config=classpath:redisson.yaml
```
### 3. Use Redisson through spring bean with `RedissonClient` interface or `RedisTemplate`/`ReactiveRedisTemplate` objects

@ -48,6 +48,7 @@ import org.springframework.util.ReflectionUtils;
*
* @author Nikita Koksharov
* @author Nikos Kakavas (https://github.com/nikakis)
* @author AnJia (https://anjia0532.github.io/)
*
*/
@Configuration
@ -56,6 +57,9 @@ import org.springframework.util.ReflectionUtils;
@EnableConfigurationProperties({RedissonProperties.class, RedisProperties.class})
public class RedissonAutoConfiguration {
private static final String REDIS_PROTOCOL_PREFIX = "redis://";
private static final String REDISS_PROTOCOL_PREFIX = "rediss://";
@Autowired(required = false)
private List<RedissonAutoConfigurationCustomizer> redissonAutoConfigurationCustomizers;
@ -108,14 +112,24 @@ public class RedissonAutoConfiguration {
}
if (redissonProperties.getConfig() != null) {
try {
config = Config.fromYAML(redissonProperties.getConfig());
} catch (IOException e) {
try {
config = Config.fromJSON(redissonProperties.getConfig());
} catch (IOException e1) {
throw new IllegalArgumentException("Can't parse config", e1);
}
}
} else if (redissonProperties.getFile() != null) {
try {
InputStream is = getConfigStream();
config = Config.fromJSON(is);
config = Config.fromYAML(is);
} catch (IOException e) {
// trying next format
try {
InputStream is = getConfigStream();
config = Config.fromYAML(is);
config = Config.fromJSON(is);
} catch (IOException e1) {
throw new IllegalArgumentException("Can't parse config", e1);
}
@ -152,10 +166,10 @@ public class RedissonAutoConfiguration {
.setPassword(redisProperties.getPassword());
} else {
config = new Config();
String prefix = "redis://";
String prefix = REDIS_PROTOCOL_PREFIX;
Method method = ReflectionUtils.findMethod(RedisProperties.class, "isSsl");
if (method != null && (Boolean)ReflectionUtils.invokeMethod(method, redisProperties)) {
prefix = "rediss://";
prefix = REDISS_PROTOCOL_PREFIX;
}
config.useSingleServer()
@ -175,8 +189,8 @@ public class RedissonAutoConfiguration {
private String[] convert(List<String> nodesObject) {
List<String> nodes = new ArrayList<String>(nodesObject.size());
for (String node : nodesObject) {
if (!node.startsWith("redis://") && !node.startsWith("rediss://")) {
nodes.add("redis://" + node);
if (!node.startsWith(REDIS_PROTOCOL_PREFIX) && !node.startsWith(REDISS_PROTOCOL_PREFIX)) {
nodes.add(REDIS_PROTOCOL_PREFIX + node);
} else {
nodes.add(node);
}

@ -20,6 +20,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
/**
*
* @author Nikita Koksharov
* @author AnJia (https://anjia0532.github.io/)
*
*/
@ConfigurationProperties(prefix = "spring.redis.redisson")
@ -27,6 +28,8 @@ public class RedissonProperties {
private String config;
private String file;
public String getConfig() {
return config;
}
@ -35,4 +38,11 @@ public class RedissonProperties {
this.config = config;
}
public String getFile() {
return file;
}
public void setFile(String file) {
this.file = file;
}
}

Loading…
Cancel
Save