commit 90ff9a54196a7354e65290c6ec8795d383edc6c8
Author: TangZhaoZhen <207525215@qq.com>
Date: Sun Oct 29 19:29:30 2023 +0800
初始化
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5ff6309
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,38 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store
\ No newline at end of file
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..35410ca
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..aa00ffa
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..8d66637
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..9e9713d
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000..2b63946
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..14e845b
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,54 @@
+
+
+ 4.0.0
+
+ com.tzz
+ redis
+ 1.0-SNAPSHOT
+
+
+
+
+ redis.clients
+ jedis
+ 3.8.0
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ 2.7.17
+
+
+
+ junit
+ junit
+ 4.12
+ compile
+
+
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+
+
+
+ 17
+ 17
+ UTF-8
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/com/tzz/redis/service/IRedisPool.java b/src/main/java/com/tzz/redis/service/IRedisPool.java
new file mode 100644
index 0000000..e44de8c
--- /dev/null
+++ b/src/main/java/com/tzz/redis/service/IRedisPool.java
@@ -0,0 +1,31 @@
+package com.tzz.redis.service;
+
+import redis.clients.jedis.Jedis;
+
+/**
+ * @author : tangzhaozhen
+ * @createTime : 2023/10/29 14:25
+ */
+
+public interface IRedisPool {
+ /***
+ * 连接池初始化
+ * @param maxTotal 最大连接数
+ * @param maxWaitMillis 最长等待时间
+ */
+ public void init(int maxTotal,long maxWaitMillis);
+
+ /**
+ * 获取连接
+ * @return
+ * @throws Exception
+ */
+ public Jedis getResource() throws Exception;
+
+ /**
+ * 释放连接
+ */
+ public void release(Jedis jedis);
+
+}
+
diff --git a/src/main/java/com/tzz/redis/service/IRedisPoolImpl.java b/src/main/java/com/tzz/redis/service/IRedisPoolImpl.java
new file mode 100644
index 0000000..2df8666
--- /dev/null
+++ b/src/main/java/com/tzz/redis/service/IRedisPoolImpl.java
@@ -0,0 +1,86 @@
+package com.tzz.redis.service;
+
+import org.springframework.stereotype.Component;
+import redis.clients.jedis.Jedis;
+
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * @author : tangzhaozhen
+ * @createTime : 2023/10/29 15:09
+ */
+@Component
+public class IRedisPoolImpl implements IRedisPool{
+ private int maxTotal;
+ private long maxWaitMillis;
+ //定义一个空闲的线程集合
+ private LinkedBlockingQueue idJedisQueue = null;
+ //定义一个添加的线程集合
+ private LinkedBlockingQueue activJedisQueue = null;
+ //总的线程连接数
+ private AtomicInteger count = new AtomicInteger();
+
+ /**
+ *
+ * @param maxTotal 最大连接数
+ * @param maxWaitMillis 最长等待时间
+ */
+ @Override
+ public void init(int maxTotal, long maxWaitMillis) {
+ this.maxTotal =maxTotal;
+ this.maxWaitMillis =maxWaitMillis;
+ idJedisQueue = new LinkedBlockingQueue(maxTotal);
+ activJedisQueue = new LinkedBlockingQueue(maxTotal);
+
+ }
+
+ @Override
+ public Jedis getResource() throws Exception {
+ //1:记录开始时间戳,用于判断超时时间
+ long startTime = System.currentTimeMillis();
+ //2:从空闲连接集合(idJedisQueue)中获取连接,将连接放入活动连接集合中(activJedisQueue)
+ Jedis redis = null;
+ while (redis==null){
+ redis = idJedisQueue.poll();
+ if (redis!=null){
+ activJedisQueue.offer(redis);
+ return redis;
+ }
+ if (count.get()