Browse Source

优化redis,切换我jredis包,不使用spring默认redis包

hfxc226 2 years ago
parent
commit
cc6a5ae6c1

+ 16 - 0
platform-common/pom.xml

@@ -51,6 +51,22 @@
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-data-redis</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>io.lettuce</groupId>
+                    <artifactId>lettuce-core</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>redis.clients</groupId>
+                    <artifactId>jedis</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+
+        <dependency>
+            <groupId>redis.clients</groupId>
+            <artifactId>jedis</artifactId>
+            <version>3.6.3</version>
         </dependency>
 
         <dependency>

+ 2 - 1
platform-opc/src/main/java/com/platform/opc/servie/OpcTaskService.java

@@ -38,7 +38,7 @@ public class OpcTaskService {
     public void getValue(){
         log.info("开始定时任务");
         List<OpcResult> resultList = OpcDAClient.getItemValuesList();
-        log.info("resultList:" + resultList.size());
+        log.info("resultList数量:" + resultList.size());
         log.info("数据存入redis");
         RedisUtils.setList("opcList", resultList);
         log.info("结束定时任务");
@@ -53,6 +53,7 @@ public class OpcTaskService {
     public void saveValue(){
         log.info("开始读取redis");
         List<OpcResult>  resultList = RedisUtils.getList("opcList", 0 , -1);
+        log.info("resultList数量:" + resultList.size());
         for(OpcResult result: resultList){
             log.info("id: " + result.getId() + ", value: " + result.getValue() + ", time: " + result.getTime());
         }

+ 1 - 1
platform-opc/src/main/java/com/platform/opc/util/OpcDAClient.java

@@ -256,8 +256,8 @@ public class OpcDAClient {
                 for (int i = 0; i < groupItemsList.size(); i++) {
                     Map<Item, ItemState> resultMap = groupList.get(i).read(true, itemArrList[i]);
                     //log.info("数据获取完成。数量:", resultMap.size() + ", 组序号:" + i);
-                    OpcResult result = new OpcResult();
                     for (Item item : resultMap.keySet()) {
+                        OpcResult result = new OpcResult();
                         ItemState itemMap = resultMap.get(item);
                         String value = getVal(itemMap.getValue());
                         result.setId(item.getId());

+ 9 - 0
platform-opc/src/main/resources/application-dev.yml

@@ -6,6 +6,15 @@ spring:
     port: 6379
     host: localhost
     database: 1
+    timeout: 0            # 连接空闲超过 N(毫秒)后关闭,0为禁用
+    # 使用jedis连接池,需要排除lettuce-core,依赖jedis
+    jedis:
+      pool:
+        max-active: 50    # 连接池最大连接数(使用负值表示没有限制)
+        max-wait: 2000    # 连接池中连接用完时,新的请求等待时间(毫秒),超过该时间抛出异常JedisConnectionException,(默认-1,负值表示没有限制,不建议使用默认值)
+        max-idle: 10      # 连接池中的最大空闲连接,默认8
+        min-idle: 1       # 连接池中的最小空闲连接,默认0
+        time-between-eviction-runs: 30000   # 逐出运行之间的时间(毫秒)
 platform:
   slf4j:
     data: D://logs

+ 8 - 0
platform-opc/src/main/resources/application-prod.yml

@@ -6,6 +6,14 @@ spring:
     port: 6379
     host: localhost
     database: 2
+    # 使用jedis连接池,需要排除lettuce-core,依赖jedis
+    jedis:
+      pool:
+        max-active: 50    # 连接池最大连接数(使用负值表示没有限制)
+        max-wait: 2000    # 连接池中连接用完时,新的请求等待时间(毫秒),超过该时间抛出异常JedisConnectionException,(默认-1,负值表示没有限制,不建议使用默认值)
+        max-idle: 10      # 连接池中的最大空闲连接,默认8
+        min-idle: 1       # 连接池中的最小空闲连接,默认0
+        time-between-eviction-runs: 30000   # 逐出运行之间的时间(毫秒)
 platform:
   slf4j:
     data: D://xajg

+ 8 - 0
platform-opc/src/main/resources/application-test.yml

@@ -6,6 +6,14 @@ spring:
     port: 6379
     host: localhost
     database: 3
+    # 使用jedis连接池,需要排除lettuce-core,依赖jedis
+    jedis:
+      pool:
+        max-active: 50    # 连接池最大连接数(使用负值表示没有限制)
+        max-wait: 2000    # 连接池中连接用完时,新的请求等待时间(毫秒),超过该时间抛出异常JedisConnectionException,(默认-1,负值表示没有限制,不建议使用默认值)
+        max-idle: 10      # 连接池中的最大空闲连接,默认8
+        min-idle: 1       # 连接池中的最小空闲连接,默认0
+        time-between-eviction-runs: 30000   # 逐出运行之间的时间(毫秒)
 platform:
   slf4j:
     data: D://xajg

+ 0 - 4
platform-rest/pom.xml

@@ -67,10 +67,6 @@
             <type>pom</type>
             <scope>import</scope>
         </dependency>
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-data-redis</artifactId>
-        </dependency>
 
         <!--测试依赖-->
         <dependency>