diff --git a/README.en.md b/README.en.md
index 4c7b5f6a2ed93b068298f6ed42979a65127f1e77..a416fd85ac4592e88ee56b893b7354f690b2e449 100644
--- a/README.en.md
+++ b/README.en.md
@@ -21,7 +21,7 @@ Dependency spring-boot-starter-data-redis
wiki.xsx
spring-boot-starter-fast-redis
- 1.5.1
+ 1.5.2
```
#### Document
@@ -59,7 +59,7 @@ d
org.redisson
redisson-spring-data-21
- 3.10.7
+ 3.11.0
```
##### redisson config:
diff --git a/README.md b/README.md
index f5a3385c75e794f85c69ffbc36f1fdd59ce3ab35..4a9bca0c044c8c4f0915ae3fd1a703d765ebf233 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@
wiki.xsx
spring-boot-starter-fast-redis
- 1.5.1
+ 1.5.2
```
@@ -61,7 +61,7 @@ https://apidoc.gitee.com/xsxgit/spring-boot-starter-fast-redis
org.redisson
redisson-spring-data-21
- 3.10.7
+ 3.11.0
直接调用API:
diff --git a/pom.xml b/pom.xml
index 005a2afa110a2ffb6dfee574347badf5e723e250..e8b3c534469ca1ff2ce4d52059668374a5c86866 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
wiki.xsx
spring-boot-starter-fast-redis
- 1.5.1
+ 1.5.2
jar
spring-boot-starter-fast-redis
http://www.xsx.wiki
diff --git a/src/main/java/wiki/xsx/core/handler/CommonHandler.java b/src/main/java/wiki/xsx/core/handler/CommonHandler.java
deleted file mode 100644
index f645909b989c06e2c9388322801dc2e740f82856..0000000000000000000000000000000000000000
--- a/src/main/java/wiki/xsx/core/handler/CommonHandler.java
+++ /dev/null
@@ -1,314 +0,0 @@
-package wiki.xsx.core.handler;
-
-import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.data.redis.core.StringRedisTemplate;
-import wiki.xsx.core.util.ApplicationContextUtil;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.concurrent.ConcurrentMap;
-
-/**
- * 通用助手
- * @author xsx
- * @date 2019/4/25
- * @since 1.8
- */
-public class CommonHandler {
- /**
- * 助手管理实例
- */
- private static final HandlerManager MANAGER = HandlerManager.getManager();
- /**
- * 通用助手实例
- */
- private static final CommonHandler HANDLER = new CommonHandler();
-
- /**
- * 通用助手构造
- */
- private CommonHandler() {
- int dbIndex = getInitDBIndex();
- initDBHandler(dbIndex);
- initKeyHandler(dbIndex);
- initNumberHandler(dbIndex);
- initStringHandler(dbIndex);
- initListHandler(dbIndex);
- initHashHandler(dbIndex);
- initSetHandler(dbIndex);
- initZsetHandler(dbIndex);
- initBitmapHandler(dbIndex);
- initGeoHandler(dbIndex);
- initHyperLogLogHandler(dbIndex);
- initScriptHandler(dbIndex);
- initPubSubHandler(dbIndex);
- initSentinelHandler(dbIndex);
- initCustomCommandHandler(dbIndex);
- }
-
- /**
- * 获取助手实例
- * @return 返回助手实例
- */
- public static CommonHandler getInstance() {
- return HANDLER;
- }
-
- /**
- * 获取默认KEY
- * @return 返回默认KEY
- */
- public String getDefaultKey() {
- return MANAGER.getDefaultKey();
- }
-
- /**
- * 获取助手
- * @param key KEY
- * @param type 助手类型
- * @return 返回助手
- */
- public RedisHandler getHandler(String key, HandlerType type) {
- // 若是集群助手类型,则直接返回
- if (type==HandlerType.CLUSTER) {
- return MANAGER.getClusterHandler();
- }
- ConcurrentMap map = MANAGER.getHandlerMap(type);
- RedisHandler handler = map.get(key);
- if (handler!=null) {
- return handler;
- }
- synchronized (MANAGER) {
- handler = map.get(key);
- if (handler==null) {
- RedisHandler instance = this.getHandlerInstance(key, type);
- handler = map.putIfAbsent(key, instance);
- if (handler==null) {
- handler = instance;
- }
- }
- }
- return handler;
- }
-
- /**
- * 获取默认对象模板
- * @return 返回对象模板
- */
- public RedisTemplate getDefaultRedisTemplate() {
- return HandlerManager.getDefaultRedisTemplate();
- }
-
- /**
- * 获取默认字符串模板
- * @return 返回字符串模板
- */
- public StringRedisTemplate getDefaultStringRedisTemplate() {
- return HandlerManager.getDefaultStringRedisTemplate();
- }
-
- /**
- * 获取初始化数据库索引
- * @return 返回数据库索引
- */
- private int getInitDBIndex() {
- return ApplicationContextUtil.getContext().getBean(RedisProperties.class).getDatabase();
- }
-
- /**
- * 初始化数据库助手
- * @param dbIndex 数据库索引
- */
- private void initDBHandler(int dbIndex) {
- ConcurrentMap dbMap = MANAGER.getHandlerMap(HandlerType.DB);
- DBHandler handler = new DBHandler(dbIndex);
- dbMap.put(getDefaultKey(), handler);
- dbMap.put(String.valueOf(dbIndex), handler);
- }
-
- /**
- * 初始化键助手
- * @param dbIndex 数据库索引
- */
- private void initKeyHandler(int dbIndex) {
- ConcurrentMap keyMap = MANAGER.getHandlerMap(HandlerType.KEY);
- KeyHandler handler = new KeyHandler(dbIndex);
- keyMap.put(getDefaultKey(), handler);
- keyMap.put(String.valueOf(dbIndex), handler);
- }
-
- /**
- * 初始化数字助手
- * @param dbIndex 数据库索引
- */
- private void initNumberHandler(int dbIndex) {
- ConcurrentMap numberMap = MANAGER.getHandlerMap(HandlerType.NUMBER);
- NumberHandler handler = new NumberHandler(dbIndex);
- numberMap.put(getDefaultKey(), handler);
- numberMap.put(String.valueOf(dbIndex), handler);
- }
-
- /**
- * 初始化字符串助手
- * @param dbIndex 数据库索引
- */
- private void initStringHandler(int dbIndex) {
- ConcurrentMap stringMap = MANAGER.getHandlerMap(HandlerType.STRING);
- StringHandler handler = new StringHandler(dbIndex);
- stringMap.put(getDefaultKey(), handler);
- stringMap.put(String.valueOf(dbIndex), handler);
- }
-
- /**
- * 初始化列表助手
- * @param dbIndex 数据库索引
- */
- private void initListHandler(int dbIndex) {
- ConcurrentMap listMap = MANAGER.getHandlerMap(HandlerType.LIST);
- ListHandler handler = new ListHandler(dbIndex);
- listMap.put(getDefaultKey(), handler);
- listMap.put(String.valueOf(dbIndex), handler);
- }
-
- /**
- * 初始化哈希助手
- * @param dbIndex 数据库索引
- */
- private void initHashHandler(int dbIndex) {
- ConcurrentMap hashMap = MANAGER.getHandlerMap(HandlerType.HASH);
- HashHandler handler = new HashHandler(dbIndex);
- hashMap.put(getDefaultKey(), handler);
- hashMap.put(String.valueOf(dbIndex), handler);
- }
-
- /**
- * 初始化无序集合助手
- * @param dbIndex 数据库索引
- */
- private void initSetHandler(int dbIndex) {
- ConcurrentMap setMap = MANAGER.getHandlerMap(HandlerType.SET);
- SetHandler handler = new SetHandler(dbIndex);
- setMap.put(getDefaultKey(), handler);
- setMap.put(String.valueOf(dbIndex), handler);
- }
-
- /**
- * 初始化有序集合助手
- * @param dbIndex 数据库索引
- */
- private void initZsetHandler(int dbIndex) {
- ConcurrentMap zsetMap = MANAGER.getHandlerMap(HandlerType.ZSET);
- ZsetHandler handler = new ZsetHandler(dbIndex);
- zsetMap.put(getDefaultKey(), handler);
- zsetMap.put(String.valueOf(dbIndex), handler);
- }
-
- /**
- * 初始化位图助手
- * @param dbIndex 数据库索引
- */
- private void initBitmapHandler(int dbIndex) {
- ConcurrentMap bitmapMap = MANAGER.getHandlerMap(HandlerType.BITMAP);
- BitmapHandler handler = new BitmapHandler(dbIndex);
- bitmapMap.put(getDefaultKey(), handler);
- bitmapMap.put(String.valueOf(dbIndex), handler);
- }
-
- /**
- * 初始化地理位置助手
- * @param dbIndex 数据库索引
- */
- private void initGeoHandler(int dbIndex) {
- ConcurrentMap geoMap = MANAGER.getHandlerMap(HandlerType.GEO);
- GeoHandler handler = new GeoHandler(dbIndex);
- geoMap.put(getDefaultKey(), handler);
- geoMap.put(String.valueOf(dbIndex), handler);
- }
-
- /**
- * 初始化基数助手
- * @param dbIndex 数据库索引
- */
- private void initHyperLogLogHandler(int dbIndex) {
- ConcurrentMap hyperLogLogMap = MANAGER.getHandlerMap(HandlerType.HYPERLOGLOG);
- HyperLogLogHandler handler = new HyperLogLogHandler(dbIndex);
- hyperLogLogMap.put(getDefaultKey(), handler);
- hyperLogLogMap.put(String.valueOf(dbIndex), handler);
- }
-
- /**
- * 初始化lua脚本助手
- * @param dbIndex 数据库索引
- */
- private void initScriptHandler(int dbIndex) {
- ConcurrentMap scriptMap = MANAGER.getHandlerMap(HandlerType.SCRIPT);
- ScriptHandler handler = new ScriptHandler(dbIndex);
- scriptMap.put(getDefaultKey(), handler);
- scriptMap.put(String.valueOf(dbIndex), handler);
- }
-
- /**
- * 初始化发布订阅助手
- * @param dbIndex 数据库索引
- */
- private void initPubSubHandler(int dbIndex) {
- ConcurrentMap pubSubMap = MANAGER.getHandlerMap(HandlerType.PUBSUB);
- PubSubHandler handler = new PubSubHandler(dbIndex);
- pubSubMap.put(getDefaultKey(), handler);
- pubSubMap.put(String.valueOf(dbIndex), handler);
- }
-
- /**
- * 初始化分布式锁助手
- * @param dbIndex 数据库索引
- */
- private void initRedisLockHandler(int dbIndex) {
- ConcurrentMap lockMap = MANAGER.getHandlerMap(HandlerType.REDISLOCK);
- RedisLockHandler handler = new RedisLockHandler(dbIndex);
- lockMap.put(getDefaultKey(), handler);
- lockMap.put(String.valueOf(dbIndex), handler);
- }
-
- /**
- * 初始化哨兵助手
- * @param dbIndex 数据库索引
- */
- private void initSentinelHandler(int dbIndex) {
- ConcurrentMap sentinelMap = MANAGER.getHandlerMap(HandlerType.SENTINEL);
- SentinelHandler handler = new SentinelHandler(dbIndex);
- sentinelMap.put(getDefaultKey(), handler);
- sentinelMap.put(String.valueOf(dbIndex), handler);
- }
-
- /**
- * 初始化自定义命令助手
- * @param dbIndex 数据库索引
- */
- private void initCustomCommandHandler(int dbIndex) {
- ConcurrentMap customCommandMap = MANAGER.getHandlerMap(HandlerType.CUSTOMCOMMAND);
- CustomCommandHandler handler = new CustomCommandHandler(dbIndex);
- customCommandMap.put(getDefaultKey(), handler);
- customCommandMap.put(String.valueOf(dbIndex), handler);
- }
-
- /**
- * 获取助手实例
- * @param key KEY
- * @param type 助手类型
- * @return 返回实例
- */
- @SuppressWarnings("unchecked")
- private RedisHandler getHandlerInstance(String key, HandlerType type) {
- Class clz = type.getTypeClass();
- try {
- Constructor constructor = clz.getDeclaredConstructor(Integer.class);
- constructor.setAccessible(true);
- return (RedisHandler) constructor.newInstance(Integer.valueOf(key));
- } catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
- e.printStackTrace();
- }
- return null;
- }
-
-}
diff --git a/src/main/java/wiki/xsx/core/handler/DBHandler.java b/src/main/java/wiki/xsx/core/handler/DBHandler.java
index c738f0fde39258c578acd0ae96d8c2abe55b1dfa..dac333f647c3b69648c0778dcf0c2c2a6659437f 100644
--- a/src/main/java/wiki/xsx/core/handler/DBHandler.java
+++ b/src/main/java/wiki/xsx/core/handler/DBHandler.java
@@ -5,8 +5,9 @@ import org.slf4j.LoggerFactory;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisServerCommands;
import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.data.redis.core.StringRedisTemplate;
+import org.springframework.data.redis.core.types.RedisClientInfo;
import org.springframework.data.redis.serializer.RedisSerializer;
+import wiki.xsx.core.util.RedisUtil;
import java.time.Clock;
import java.util.Arrays;
@@ -99,10 +100,6 @@ public final class DBHandler implements RedisHandler {
* 对象模板
*/
private RedisTemplate redisTemplate;
- /**
- * 字符串模板
- */
- private StringRedisTemplate stringRedisTemplate;
/**
* 数据库索引
*/
@@ -115,9 +112,7 @@ public final class DBHandler implements RedisHandler {
@SuppressWarnings("unchecked")
DBHandler(Integer dbIndex) {
this.dbIndex = dbIndex;
- List templateList = HandlerManager.createTemplate(dbIndex);
- this.redisTemplate = templateList.get(0);
- this.stringRedisTemplate = (StringRedisTemplate) templateList.get(1);
+ this.redisTemplate = HandlerManager.createRedisTemplate(dbIndex);
}
/**
@@ -129,73 +124,6 @@ public final class DBHandler implements RedisHandler {
return this.dbIndex;
}
- /**
- * 检查连接
- * @see Redis Documentation: PING
- * @since redis 1.0.0
- * @return 返回延迟时间(ms)
- */
- public Long ping() {
- RedisConnection connection = this.redisTemplate.getRequiredConnectionFactory().getConnection();
- long begin = CLOCK.millis();
- connection.ping();
- long end = CLOCK.millis();
- return end - begin;
- }
-
- /**
- * 服务器时间
- * @see Redis Documentation: TIME
- * @since redis 2.6.0
- * @return 返回服务器时间(ms)
- */
- public Long time() {
- return this.redisTemplate.getRequiredConnectionFactory().getConnection().serverCommands().time();
- }
-
- /**
- * 测试打印
- * @see Redis Documentation: ECHO
- * @since redis 1.0.0
- * @param message 信息
- * @return 返回打印信息
- */
- public String echo(String message) {
- RedisSerializer serializer = RedisSerializer.string();
- return serializer.deserialize(
- this.redisTemplate
- .getRequiredConnectionFactory()
- .getConnection()
- .echo(serializer.serialize(message))
- );
- }
-
- /**
- * 清理当前数据库
- * @see Redis Documentation: FLUSHDB
- * @since redis 1.0.0
- */
- public void clearDB() {
- try {
- this.redisTemplate.getRequiredConnectionFactory().getConnection().serverCommands().flushDb();
- }catch (IllegalStateException e) {
- log.error(e.getMessage());
- }
- }
-
- /**
- * 清理所有数据库
- * @see Redis Documentation: FLUSHALL
- * @since redis 1.0.0
- */
- public void clearDBAll() {
- try {
- this.redisTemplate.getRequiredConnectionFactory().getConnection().serverCommands().flushAll();
- }catch (IllegalStateException e) {
- log.error(e.getMessage());
- }
- }
-
/**
* 获取当前数据库信息
* @see Redis Documentation: INFO
@@ -233,6 +161,32 @@ public final class DBHandler implements RedisHandler {
return serverCommands.info(DBOption.DEFAULT.option);
}
+ /**
+ * 清理当前数据库
+ * @see Redis Documentation: FLUSHDB
+ * @since redis 1.0.0
+ */
+ public void clearDB() {
+ try {
+ this.redisTemplate.getRequiredConnectionFactory().getConnection().serverCommands().flushDb();
+ }catch (IllegalStateException e) {
+ log.error(e.getMessage());
+ }
+ }
+
+ /**
+ * 清理所有数据库
+ * @see Redis Documentation: FLUSHALL
+ * @since redis 1.0.0
+ */
+ public void clearDBAll() {
+ try {
+ this.redisTemplate.getRequiredConnectionFactory().getConnection().serverCommands().flushAll();
+ }catch (IllegalStateException e) {
+ log.error(e.getMessage());
+ }
+ }
+
/**
* 设置数据库配置参数
* @see Redis Documentation: CONFIG SET
@@ -249,6 +203,7 @@ public final class DBHandler implements RedisHandler {
* @see Redis Documentation: CONFIG GET
* @since redis 2.0.0
* @param param 参数名
+ * @return 返回数据库配置信息
*/
public Properties getConfig(String param) {
return this.redisTemplate.getRequiredConnectionFactory().getConnection().getConfig(param);
@@ -264,139 +219,123 @@ public final class DBHandler implements RedisHandler {
}
/**
- * 设置对象客户端连接名称
+ * 设置客户端连接名称
* @see Redis Documentation: CLIENT SETNAME
* @since redis 2.6.9
* @param name 名称
*/
- public void setClientNameAsObj(String name) {
+ public void setClientName(String name) {
this.redisTemplate
- .getRequiredConnectionFactory()
- .getConnection()
- .setClientName(RedisSerializer.string().serialize(name));
+ .getRequiredConnectionFactory()
+ .getConnection()
+ .setClientName(RedisSerializer.string().serialize(name));
}
/**
- * 设置字符串客户端连接名称
- * @see Redis Documentation: CLIENT SETNAME
+ * 获取客户端连接名称
+ * @see Redis Documentation: CLIENT GETNAME
* @since redis 2.6.9
- * @param name 名称
+ * @return 返回客户端连接名称
*/
- public void setClientName(String name) {
- this.stringRedisTemplate
- .getRequiredConnectionFactory()
- .getConnection()
- .setClientName(RedisSerializer.string().serialize(name));
+ public String getClientName() {
+ return this.redisTemplate.getRequiredConnectionFactory().getConnection().getClientName();
}
/**
- * 获取对象客户端连接名称
- * @see Redis Documentation: CLIENT GETNAME
- * @since redis 2.6.9
+ * 获取客户端连接列表
+ * @return 返回客户端连接列表
*/
- public String getClientNameAsObj() {
- return this.redisTemplate.getRequiredConnectionFactory().getConnection().getClientName();
+ public List getClientList() {
+ return this.redisTemplate.getRequiredConnectionFactory().getConnection().getClientList();
}
/**
- * 获取字符串客户端连接名称
- * @see Redis Documentation: CLIENT GETNAME
- * @since redis 2.6.9
+ * 关闭客户端
+ * @param ip 客户端IP
+ * @param port 客户端端口
*/
- public String getClientName() {
- return this.stringRedisTemplate.getRequiredConnectionFactory().getConnection().getClientName();
+ public void killClient(String ip, int port) {
+ this.redisTemplate.killClient(ip, port);
}
/**
- * 标记一个对象事务块的开始
- * @since redis 1.2.0
- * @see Redis Documentation: MULTI
+ * 角色的信息
+ * @see Redis Documentation: ROLE
+ * @since redis 2.8.12
+ * @return 返回当前是master,slave还是sentinel
*/
- public void beginTransactionAsObj() {
- this.redisTemplate.multi();
+ @SuppressWarnings("unchecked")
+ public String getRole() {
+ CustomCommandHandler commandHandler = RedisUtil.getCustomCommandHandler(this.dbIndex);
+ List