|
@@ -0,0 +1,40 @@
|
|
|
|
|
+package com.qqflow.engine.config;
|
|
|
|
|
+
|
|
|
|
|
+import org.redisson.Redisson;
|
|
|
|
|
+import org.redisson.api.RedissonClient;
|
|
|
|
|
+import org.redisson.config.Config;
|
|
|
|
|
+import org.redisson.config.SingleServerConfig;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * Redisson 分布式锁/缓存客户端配置。
|
|
|
|
|
+ * 直接读取环境变量,不依赖 Spring Boot 自动配置,
|
|
|
|
|
+ * 避免不同版本 redisson-spring-boot-starter 的属性前缀差异。
|
|
|
|
|
+ */
|
|
|
|
|
+@Configuration
|
|
|
|
|
+public class RedissonConfig {
|
|
|
|
|
+
|
|
|
|
|
+ private static final String DEFAULT_HOST = "localhost";
|
|
|
|
|
+ private static final int DEFAULT_PORT = 6379;
|
|
|
|
|
+ private static final int DEFAULT_TIMEOUT = 5000;
|
|
|
|
|
+
|
|
|
|
|
+ @Bean(destroyMethod = "shutdown")
|
|
|
|
|
+ public RedissonClient redissonClient(
|
|
|
|
|
+ @Value("${SPRING_REDIS_HOST:" + DEFAULT_HOST + "}") String host,
|
|
|
|
|
+ @Value("${SPRING_REDIS_PORT:" + DEFAULT_PORT + "}") int port,
|
|
|
|
|
+ @Value("${SPRING_REDIS_PASSWORD:}") String password) {
|
|
|
|
|
+
|
|
|
|
|
+ Config config = new Config();
|
|
|
|
|
+ SingleServerConfig serverConfig = config.useSingleServer()
|
|
|
|
|
+ .setAddress("redis://" + host + ":" + port)
|
|
|
|
|
+ .setTimeout(DEFAULT_TIMEOUT);
|
|
|
|
|
+
|
|
|
|
|
+ if (password != null && !password.isEmpty()) {
|
|
|
|
|
+ serverConfig.setPassword(password);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return Redisson.create(config);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|