From 8c12bbbf711732e52e322fe7d8b95f9f887513d5 Mon Sep 17 00:00:00 2001
From: fwq <582742538@qq.com>
Date: 星期五, 03 二月 2023 17:06:30 +0800
Subject: [PATCH] poi4.0+

---
 src/main/java/com/hx/redis/RedisUtil.java |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/hx/redis/RedisUtil.java b/src/main/java/com/hx/redis/RedisUtil.java
index 8067593..e17cf25 100644
--- a/src/main/java/com/hx/redis/RedisUtil.java
+++ b/src/main/java/com/hx/redis/RedisUtil.java
@@ -1,5 +1,6 @@
 package com.hx.redis;
 
+import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Component;
 
@@ -23,6 +24,18 @@
     @Resource
     private RedisTemplate<String, Object> redisTemplate;
 
+    /**
+     * 鍒囨崲鏁版嵁搴�
+     * @param dataNumber 鏁版嵁搴撶紪鍙�
+     */
+    public void setDataBase(int dataNumber) {
+        LettuceConnectionFactory connectionFactory = (LettuceConnectionFactory) redisTemplate.getConnectionFactory();
+        if (connectionFactory != null && dataNumber != connectionFactory.getDatabase()) {
+            connectionFactory.setDatabase(dataNumber);
+            this.redisTemplate.setConnectionFactory(connectionFactory);
+            connectionFactory.resetConnection();
+        }
+    }
 
     /**
      * [鍒ゆ柇key鏄惁瀛樺湪]

--
Gitblit v1.8.0