Przeglądaj źródła

Revert: 统一引用Redis工具包

v_HuilingDeng 3 lat temu
rodzic
commit
48039ed7e8

+ 41 - 0
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/infrastructure/config/JedisConfig.java

@@ -0,0 +1,41 @@
+package com.abi.qms.platform.infrastructure.config;
+
+import com.abi.qms.platform.infrastructure.properties.JedisPoolProperties;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import redis.clients.jedis.JedisPool;
+import redis.clients.jedis.JedisPoolConfig;
+
+@Configuration
+public class JedisConfig {
+
+    @Autowired
+    private RedisProperties redisProperties;
+
+    @Autowired
+    private JedisPoolProperties jedisPoolProperties;
+
+
+    @Bean
+    public JedisPool jedisPool() {
+        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
+
+        jedisPoolConfig.setMaxIdle(jedisPoolProperties.getMaxIdle());
+        jedisPoolConfig.setMinIdle(jedisPoolProperties.getMinIdle());
+        jedisPoolConfig.setMaxWaitMillis(jedisPoolProperties.getMaxWait());
+        jedisPoolConfig.setMaxTotal(jedisPoolProperties.getMaxActive());
+
+        JedisPool jedisPool = new JedisPool(
+                jedisPoolConfig
+                , redisProperties.getHost()
+                , redisProperties.getPort()
+                // , redisProperties.getTimeout()
+                // , redisProperties.getPassword()
+                // , redisProperties.getDatabase()
+        );
+
+        return jedisPool;
+    }
+}

+ 18 - 0
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/infrastructure/properties/JedisPoolProperties.java

@@ -0,0 +1,18 @@
+package com.abi.qms.platform.infrastructure.properties;
+
+import lombok.Data;
+import org.springframework.stereotype.Component;
+
+@Component
+@Data
+public class JedisPoolProperties {
+
+    //@Value(value = "${spring.redis.jedis.pool.max-idle}")
+    private int maxIdle;
+    //@Value(value = "${spring.redis.jedis.pool.min-idle}")
+    private int minIdle;
+    //@Value(value = "${spring.redis.jedis.pool.max-active}")
+    private int maxActive;
+    //@Value(value = "${spring.redis.jedis.pool.max-wait}")
+    private int maxWait;
+}